This article mainly introduces the contents of the PHP index array and associative array, has a certain reference value, now share to everyone, the need for friends can refer to
Recently encountered a bug, record
Define an array $arr = Array (' A ', ' B ', ' C ', ' d ');//To JSON string $str1 = Json_encode ($arr);//Remove a unset ($arr [1]);//Turn JSON$STR2 = Json_ Encode ($arr); Var_dump ($str 1); Echo ' <br/> '; Var_dump ($str 2);
String (+) "[" A "," B "," C "," D "]"
String "{" 0 ":" A "," 2 ":" C "," 3 ":" D "}"
The printed result shows that one is an array and one is an object.
Obviously the first one is an indexed array, the second is an associative array. Indexed array to JSON is an array, associative array to JSON is an object.
Deleting an array element directly using unset () will convert the indexed array to an associative array
To delete an element, keep an indexed method:
Unset ($arr [1]); Array_values ($arr);
Array_splice ($array, 1, 1);