This article describes the PHP array index and key manipulation techniques. Share to everyone for your reference. Specifically as follows:
?
1 2 3 4 5 |
<?php $array = Array ("A", "B", "C"); Defines the array $array [] = "Simon"; Adds a new array element to the Print_r ($array); Output array?> |
?
1 2 3 4 5 |
<?php $array = Array ("A", "B", "C"); Defines the array $array [9] = "Simon"; Adds a new array element to the Print_r ($array); Output array?> |
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23-24 |
<?php//Create a simple array $array = Array (0=>1, 1=>2, 2=>3, 3=>4, 6=>5); Print_r ($array); Now update the value of the key in the array to 2 $array [2] = 100; Print_r ($array); Now add a key $array ["X"] = 50; Print_r ($array); Delete all keys now, but keep the structure of the array itself foreach ($array as $i => $value) {unset ($array [$i]);} print_r ($array); Add another key $array [] = 25; Print_r ($array); Re-indexing using the array_values function $array = array_values ($array); $array [] = 13; Print_r ($array);?> |
I hope this article will help you with your PHP program design.