$val){...}}"."/> $val){...}}".">

Home >Backend Development >PHP Problem >What does php traversal mean?

What does php traversal mean?

藏色散人
藏色散人Original
2020-10-08 16:44:473025browse

PHP traversal refers to traversing an array, which means taking out the elements in the array. PHP traversal statements such as "foreach($arr_m as $value){foreach($value AS $key => $val){ ...}}".

What does php traversal mean?

Recommended: "PHP Video Tutorial"

php traversal refers to traversing the array

That's it Take out the elements from the array. .

For example

$arr = array(
'a' => 1,
'b' => 2,
'c' => 3,
'd' => 4
);
foreach($a AS $k => $v)
{
echo $k.'的值是'.$v;
}

This is a 2-dimensional array, and a double-layer loop must be used. .

If you want to output more content, you can try my modified code.

<?php
$arr_m = array(
array(&#39;id&#39;=>23,&#39;name&#39;=>&#39;小红&#39;,&#39;age&#39;=>23),
array(&#39;id&#39;=>15,&#39;name&#39;=>&#39;小白&#39;,&#39;age&#39;=>21),
array(&#39;id&#39;=>12,&#39;name&#39;=>&#39;小黑&#39;,&#39;age&#39;=>31),
array(&#39;id&#39;=>2,&#39;name&#39;=>&#39;小二&#39;,&#39;age&#39;=>31)
);
$arr_id = array();
$arr_age = array();
foreach($arr_m as $value)
{
foreach($value AS $key => $val)
{
echo $key.&#39;是&#39;.$val .&#39;<br />&#39;;
}
echo &#39;<p></p>&#39;;
}
?>

The above is the detailed content of What does php traversal mean?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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