array_walk

array_walk

int array_walk ( array array, string func [, mixed userdata])

Apply a user defined function to every element of an array.
The first argument passed to the function is the array value
and second argument passed is key of the array. Any other user parameter
can be passed as third,fourth and so on.

The function called must be a user defined function and it should not be
a PHP’s Native function.

example 1

<?php

$arr = array(’hai’,'how’,'are’,'you’);

array_walk($arr,’print_me’);

function print_me($a)
{
echo $a;
echo ” “;
}

//will out put “hai how are you ”

?>

example 2 : Passing users parameter

<?php

function print_me($a,$c)
{
echo $c.$a;
echo “
“;
}

$arr = array(’blue’,'red’,'white’);

$car = ‘my car is’;

array_walk($arr,’print_me’,$car);

//will out put “my car is blue”
// my car is red
// my car is white

?>

?>

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.