Home > Backend Development > PHP Tutorial > PHP traverse two-dimensional array and multi-dimensional array code_PHP tutorial

PHP traverse two-dimensional array and multi-dimensional array code_PHP tutorial

WBOY
Release: 2016-07-20 11:01:38
Original
985 people have browsed it

PHP traverses two-dimensional arrays and multi-dimensional array codes Regarding PHP arrays, let's talk about two-dimensional arrays and multi-dimensional traversal codes. Here are three examples to test the array traversal PHP code function. ​

php tutorial traversing two-dimensional array and multi-dimensional array code
Regarding PHP arrays, let’s talk about two-dimensional arrays and multi-dimensional traversal codes. Here are three examples to test the array traversal PHP code functions.
*/

function arr_foreach ($arr) {
if (!is_array ($arr)) {
return false;
}
foreach ($arr as $key => $val ) {
if (is_array ($val)) {
arr_foreach ($val);
} else {
echo $val.'
';
}
}
}

$arr1 = array (1=>array(11,12,13,14=>array(141,142)),2,3,4,5);
arr_foreach ($arr1);

//php traverses multi-dimensional arrays

$array = array('a'=>"'as","b"=>array('c'=>"'cc","n"=>array('1'=>" 'sdf")),'f'=>array('c'=>"'sdf","g"=>array("c")));
function handleeach(&$array,$functionname)
{
foreach($array as $k=>$v)
{
           if(is_array($v))
           {
               handleeach(&$array[$k],$functionname);
}
        else
$array[$k] = $functionname($v);
}
}
handleeach($array,'strips tutorial lashes');
print_r($array);

//Example 3, traversing a two-dimensional array

$employee[]=array("jas,join",");
$employee[]=array("june,join","programmer",20);
$employee[]=array("aili,join","programmer",20);
$employee[]=array("doe,jane","programmer",20);

$newname = array();

foreach ($employee as $record){

$newname[] = isset($record[0]) ? $record[0] : 'no name';

}

?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445432.htmlTechArticlephp traversing two-dimensional array and multi-dimensional array code Regarding php arrays, let’s talk about two-dimensional arrays and multi-dimensional arrays The traversal code, here are three examples to test the array traversal php code function...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template