PHP foreach loop

PHP foreach loop

foreach loop through the array is used.

grammar

foreach ($array as $value)
{
    要执行代码;
}

Once every cycle, the current value of the array elements will be assigned to the variable $ value (array pointer is moved one by one.

Examples

<?php $x=array("one","two","three"); foreach ($x as $key=>$value) {    
  echo $key.'-'.$value . "<br>"; 
} 
?>
  
//输出
1-one
2-two
3-three
Published 88 original articles · won praise 145 · Views 8933

Guess you like

Origin blog.csdn.net/qq_45163122/article/details/104649127