<? PHP $ names = array (3.5, 5, "hello"); echo "the array size is :". count ($ names); For ($ I = 0; $ I <7; $ I ++) {echo "<br/> the elements in the array are :". $ Names [$ I]. "<br/>" ;}?>
Note: arrays in PHP are different from arrays in Java. arrays defined in PHP can be stored in multiple data types,
In the preceding example, you can add data such as integer data, string data, and input or decimal data.
The first method to define an array is shown above,
The following describes the second method for defining Arrays:
$ ANEM [0] = "zhaoliu ";
$ Name [1] = "zhangsan ";
$ Name [2] = "Lisi ";
$ Name [3] = "wangwu ";
As shown above, the default subscript Number of the array is used to define the array.
Next, let's take a look at the method for creating an array under the custom array:
$ Names ['zs'] = "zhangsan ";
$ Names ['LS'] = "Lisi ";
$ Names ['ww '= "wangwu ";
$ Names ['zl'] = "zhaoliu ";
Or:
$ Names = array ("Zs" => "zhangsan", "ls" => "Lisi ");
<? Phpecho "<HR/> use custom subscript to define an array <br/>"; $ names = array ("Zs" => "zhangsan ", "ls" => "Lisi"); echo "array size :". count ($ names); // Method for Traversing elements in the array foreach ($ names as $ key => $ Val) {echo "<br/> ". $ key. "= ". $ Val. "<br/>" ;}?>
To customize the traversal of the underlying array, as well as the instances output simultaneously by its key.