How to use array walk in PHP

In this article, I will explain how the array_walk() function can be used in PHP.
  • 1982

array_walk() function in PHP

  • The array_walk() function is used to run each array element in a user-define function.

  • In array_walk() function, the array's keys and values are parameters in the function.

  • In array_walk() function, the array's keys and values is returns True or False.

Syntax

array_walk(array,function,parameter)

Parameter

  • array array is required parameter. the specified array whose values are to be counted.
  • function function is required parameter. the name of the user-define function.
  • parameter parameter is optional parameter. determine a parameter define by the user.

Example

The following example show to how the array_walk() function can be used in PHP.

<html>

<body>

<h3 style="color: brown;">array_walk() function example in PHP</h3>

    <?php

    function mydemo($value,$key)

    {

    echo "C-sharpcorner $key has $value<br />";

    }

    $a=array("tutorial1"=>"PHP","tutorial2"=>"ASP.NET","tutorial3"=>"JSP");

    array_walk($a,"mydemo");

    ?>

</body>

</html>

 

Output

walk.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.