English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_walk() Function Usage and Example

PHP Array Function Manual

The array_walk() function uses a user-defined function to perform callback processing on each element of the array

Syntax

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

Definition and Usage

 Apply the user-defined function funcname to each element of the array.
array_walk() is not affected by the internal array pointer of the array. array_walk() will traverse the entire array regardless of the pointer position.

Return Value

  Returns TRUE on success, or FALSE on failure.

Parameter

Serial NumberParameters and Description
1

array (required)

It specifies an array.

2

funcname (required)

The name of the user-defined function.

3

Parameter (optional)

It specifies a parameter for a user-defined function.

Online Example

Use array_walk() function to get each element of the array

<?php
   function call_back_function($value,$key) {
      echo "The value of key $key is $value \n";
   }
   $input = array("a"=>"green", "b"=>"brown", "c"=>"blue", "red");
   
   array_walk($input,"call_back_function");
?>
Test and see‹/›

Output result:

The value of key a is green 
The value of key b is brown 
The value of key c is blue 
The value of key 0 is red

  PHP Array Function Manual