Archive for 'Fruits'

The following code snippet will show you how to apply custom function recursively to every member of an array:

$sweet = array('a' => 'apple', 'b' => 'banana');
$fruits = array('sweet' => $sweet, 'sour' => 'lemon');

function print_it($item, $key)
echo "$key holds $item\n";

array_walk_recursive($fruits, 'print_it');

That’s it

PHP array_walk function example

array_walk applies the user-defined function add_prefix to each element of the array fruits.

$fruits = array(“a” => “apple”, “b” => “banana”, “o” => “orange”, “g” => “grape”, “p” => “pineapple”);


array_walk($fruits, ‘add_prefix’, “Fruit”);


function add_prefix(&$item1, $key, $prefix)
$item1 = “$prefix: $item1″;

We Can Build Your App for You. Lets Get Started !