<?php
Indexed array
The first definition of an array
$arr = Array (+/-);
Var_dump ($arr);
The second definition of an array
$arr = [n/a];
Var_dump ($arr);
The third definition of an array
$arr [0] = 7;
$arr [1] = "Hello";
Var_dump ($arr);
echo $arr [2];//value
Associative arrays
$arr = Array ("name" = "Xiao Li", "sex" = "female", "age" = "20");
echo $arr ["Sex"];
Iterating through an array
For loop traversal for indexed arrays
$arr = [1,5,6,9,4,6,8];
for ($i =0; $i <count ($arr); $i + +) {
echo $arr [$i]. ' <br> ';
} ;
Foreach Loop traversal applies to indexes and associative arrays
$arr = Array ("name" = "Xiao Li", "sex" = "female", "age" = "20");
foreach ($arr as $k = = $v) {
echo $k. ': ' $v. ' <br> ';
echo "{$k}:{$v}<br>";
};
$arr = [1,5,6,9,4,6,8];
foreach ($arr as $k) {
echo $k. ' <br> ';
};
$arr = Array ("name" = "Xiao Li", "sex" = "female", "age" = "20");
Var_dump (each ($arr));
List ($a, $b) = Array (name, Xiao Li);
echo "{$a},{$b}";
list and each combine traversal
/* $arr = Array ("name" = "Xiao Li", "sex" = "female", "age" = "20");
while (list ($k, $v) =each ($arr)) {
echo "{$k}:{$v}<br>";
} */
pointer Traversal
/* $arr = Array ("name" = "Xiao Li", "sex" = "female", "age" = "20");
Echo current ($arr);//Take value
echo Key ($arr);//Take Key
Next ($arr);
Echo current ($arr);
echo Key ($arr);
Prev ($arr);
Echo current ($arr);
echo Key ($arr);
End ($arr);
Echo current ($arr);
echo Key ($arr);
Reset ($arr);
echo Key ($arr). ': '. Current ($arr). ' <br> '; */
Basic operations for PHP arrays and classic operations for iterating over arrays