element()

element($item, $array[, $default = NULL])

Parameters:
  • $item (string) – Item to fetch from the array
  • $array (array) – Input array
  • $default (bool) – What to return if the array isn’t valid
Returns:

NULL on failure or the array item.

Return type:

mixed

Lets you fetch an item from an array. The function tests whether the array index is set and whether it has a value. If a value exists it is returned. If a value does not exist it returns NULL, or whatever you’ve specified as the default value via the third parameter.

Example:

$array = array(
        'color' => 'red',
        'shape' => 'round',
        'size'  => ''
);

echo element('color', $array); // returns "red"
echo element('size', $array, 'foobar'); // returns "foobar"
doc_CodeIgniter
2016-10-15 16:32:16
Comments
Leave a Comment

Please login to continue.