//Create an array whose values can be placed in any data type
$arr [0]=111;
$arr [1]=121;
$arr [2]= "Nihao";
$arr [3]=141.9;
$arr [4]=null; The //null is to be recorded in length and takes up space, but does not output
echo "Array Length". Count ($arr);
//Iterate through the values in the array
for ($i =0; $i <count ($arr); $i + +) {
echo "<br/>". $arr [$i];
}
- Create array second way &N Bsp , &NB Sp , &NB Sp , &NB Sp , &NB Sp
$arr =array (' Hello ', ' Niho ', 12.3, 1); br> //traverse the values in the array
for ($i =0; $i <count ($arr); $i + +) {
echo "<br/>". $arr [$i];
}
- The third way to create an array "How to Key Values" (by default, our element subscript is starting from 0, but can also be defined by itself) , , &NB Sp , &NB Sp cases are as follows: &NBSP ; , &NB Sp , &NB Sp , &NB Sp , &NB Sp; , &NB Sp
$arr [' logo ']= ' Chengdu ';
$arr [' Add ']=123;
...
Or
$arr =array ("logo" = "Chengdu", "Add" =>123,4=>23); , &NB Sp , &NB Sp , &NB Sp , &NB Sp The tests are as follows: &NBS P , &NB Sp , &NB Sp &NBSP; , &NB Sp , &NB Sp
$arr =array ("logo" = "Chengdu", "Add" =>123,4=>23);
//iterate through the values in the array,
foreach ($arr as $val) {
the echo $val;
}
Forea CH ($arr as $key = + $value) {
echo $key. " : ". $value;
}
$arr [true]= ' Hello ';
Alert ($arr [1]);//$arr [1] equivalent to $arr[true];
$arr [null]=123; equivalent to $arr[""]=123;
- We usually use Print_r () and Var_dump () to view arrays &NB Sp , &NB Sp , &NB Sp , &NB Sp print_r ($arr);// Array ([0] = hello [1] = Niho [2] = 12.3 [3] = 1) , &N Bsp , &NB Sp var_dump ($arr);// Array (4) {[0]=> string (5) "Hello" [1]=> string (4) "Niho" [2]=> float (12.3) [3]=> int (1)}
- The length of the array in PHP can be automatically increased &NBS P , &NB Sp , &NB Sp , &NB Sp , &NB Sp Case:
$arr =array;
$arr [2]= "Zenjia";//automatically assigns a space to the array
echo $arr [2];
-
&N Bsp , &NB Sp , &NB Sp &NBSP;
-
Several important functions in the PHP array &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp 1.count (); //Statistics Array length and nbsp , &NB Sp   , &NB Sp , &NB Sp 2.is_array ()//Determine if a variable is an array &NBSP ; , &NB Sp , &NB Sp , &NB Sp , &NB Sp 3.print_r () and Var_dump (), which have been stated above , &N Bsp , &NB Sp , &NB Sp &NBSP;4.EX Plode ()//split string, for example $arr=explode (",", "a,b,c,d"); test: Print_r ($arr); , &NB Sp