<?PHP//common functions//Generate random numbers//echo rand (1,10);//two parameters to determine the range of random numbers//datetime function//var_dump (time ());//timestamp of Unix timestamp for the current time//date_default_ Timezone_set (' PRC '),//echo date ("Y-m-d h:i:s", Time ());//format date timestamp//echo date ("y-m-d h:i:s");//omit 2nd parameter get current time//array/ Features: can store any type of data, can be discontinuous, can be indexed, or can be associated//definition array (1)//$attr = Array (three-in-one); Define a simple indexed array//definition Array (2)//$attr [] = 1;//$attr [] = 2;//definition Array (3)$attr=Array("One" = "Hello", "three" =>10.9);/*$attr = Array ("Hello", "2" = "2222", "World");*///array value//echo $attr [0];//based on the index//echo $attr ["Three"];//value values based on key//traversal array//1.for loop for indexed arrays/*For ($i =0; $i <count ($attr), $i + +) {echo $attr [$i]. " <br> ";}*///2.foreach traversal, all applicable/*foreach ($attr as $v) {echo $v. <br> ";}*//*foreach ($attr as $k = + $v) {//echo $k. " --". $v." <br> "; echo "{$k}--{$v}<br>";}*///3. Use each () and list () combination to iterate through the array/*Var_dump (each ($attr));//Returns the details of the current element in the array var_dump ($ATTR); Var_dump (each ($attr) );*///list ($a, $b, $c) = $attr;//Assign each element in the right-hand array to the list () argument lists, note: The right-hand array must contain an index/*while (list ($k, $v) =each ($attr) {echo "{$k}--{$v}<br>";}*///Var_dump ($attr);?>
View Code
PHP array definitions, values, and traversal