Home > Article > Backend Development > PHP arrays and conditions, loop statement learning_PHP tutorial
1. Array
Example 1:
1). Rendering preview:
2).Code screenshot:
The following is a two-dimensional array, which is often used in practice.
$mess = array('title'=>'Message title 1','content'=>'Content','ctime'=>'2012-1-1 12:34:23'); //Associative array
//Statement to traverse the array
//The first type
foreach($mess as $v){ //foreach can traverse associative arrays; while the for loop can only traverse enumeration arrays, not associative arrays.
//$v It is the value that receives the array element. The number of iterations of the loop body is determined by the array element
echo $v.'
';
}
//The second type
foreach($mess as $k=>$v){
//$k is used to receive the key name or index corresponding to the data element, $v is to receive the array element The value of
echo $k.'-----'.$v.'
';
Example 2:
1). Rendering preview:
2).Code screenshot: