: This article describes how to create and traverse arrays in php. For more information about PHP tutorials, see. The establishment of arrays in php can be divided into three types of methods. when traversing an array, we often use the count ($ arr) function, which returns the length of the array:
1.
// Method 1 for array creation $ arr [0] = 11; $ arr [1] = "ee"; $ arr [2] = 11.1; $ arr [3] = true; $ arr [4] = null; for ($ I = 0; $ I <count ($ arr); $ I ++) {echo'
'. $ Arr [$ I];}
2.
// Method 2 for creating an array $ arr = array (1, "ee", true); for ($ I = 0; $ I <count ($ arr ); $ I ++) {echo'
'. $ Arr [$ I];}
3.
// Method 3 for creating an array (store as a key-value pair) $ arr ['name'] = "raid "; $ arr ['pwd'] = "eee"; foreach ($ arr as $ key => $ val) {echo $ key. "= ". $ val."
";}
4. sometimes you can write as follows:
$ Arr = array (5 => "logo", "ee" => 12, "ff" => 13); // display the overall array of print_r ($ arr ); echo"
"; Var_dump ($ arr); echo"
". Is_array ($ arr );
To split the string into arrays, we can use the following explode method:
$str = "e a d d";$arr = explode(" ", $str);foreach($arr as $key=>$val) {echo "
".$key."=".$val;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces the establishment and traversal of arrays in php, including the content, and hope to be helpful to friends who are interested in PHP tutorials.