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

What does php traversal mean?

藏色散人
Release: 2023-03-06 14:26:02
Original
3029 people have browsed it

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;
}
Copy after login

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;;
}
?>
Copy after login

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!

Related labels:
php
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