Monday 26 August 2013

PHP Function array_walk()

Syntax

array_walk ( $array, $funcname [, $parameter] );

Definition and Usage

This function returns an array containing all the values of array1 that are present in all the arguments array2, array3.

Paramters

ParameterDescription
arrayRequired. Specifies an array.
funcnameRequired. The name of the user-made function.
paramterOptional. Specifies a parameter to the user-made function.

Example

Try out following example:
<?php
function call_back_function($value,$key) 
{
  echo "The key $key has the value $value<br />";
}

$array = array("a"=>"green", "b"=>"brown", "c"=>"blue", "red");

array_walk($array,"call_back_function");
?> 
This will produce following result:
The key a has the value green
The key b has the value brown
The key c has the value blue
The key 0 has the value red

No comments:

Post a Comment