How to use array walk recursive in PHP

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

array_walk_recursive() function in PHP

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

  • The array_walk_recursive() function can work with inside an array.

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

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

Syntax

array_walk_recursive(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_recursive() function can be used in PHP.

<html>

<body>

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

    <?php

    function mydemo($value,$key)

    {

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

    }

    $a1=array("Tutorial1"=>"ASP.NET","Tutorial2"=>"Java");

    $a2=array($a1,"Article1"=>"JavaScript","Article2"=>"Php");

    array_walk_recursive($a2,"mydemo");

    ?>

</body>

</html>

 

Output

wlakrecursivephp.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.