05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Creates an array containing all values from the original array for which the given callback<br />

function returns true. If the input array is an associative array, the keys are preserved. For<br />

example:<br />

function isBig($inValue) {<br />

return($inValue > 10);<br />

}<br />

$array = array(7, 8, 9, 10, 11, 12, 13, 14);<br />

$new_array = array_filter($array, "isBig"); // contains (11, 12, 13, 14)<br />

array_flip<br />

array array_flip(array array)<br />

Returns an array in which the elements’ keys are the original array’s values, and vice versa.<br />

If multiple values are found, the last one encountered is retained. If any of the values in the<br />

original array are any type except strings and integers, array_flip( ) returns false.<br />

array_intersect<br />

array array_intersect(array array1, array array2[, ... array arrayN])<br />

Returns an array whose elements are those from the first array that also exist in every other<br />

array.<br />

array_keys<br />

array array_keys(array array[, mixed value])<br />

Returns an array containing all of the keys in the given array. If the second parameter is<br />

provided, only keys whose values match value are returned in the array.<br />

array_map<br />

array array_map(mixed callback, array array1[, ... array arrayN])<br />

Creates an array by applying the callback function referenced in the first parameter to the<br />

remaining parameters; the callback function should take as parameters a number of values<br />

equal to the number of arrays passed into array_map( ). For example:<br />

function multiply($inOne, $inTwo) {<br />

return $inOne * $inTwo;<br />

}<br />

$first = (1, 2, 3, 4);<br />

$second = (10, 9, 8, 7);<br />

$array = array_map("multiply", $first, $second); // contains (10, 18, 24, 28)<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

array_map | 379

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!