This article describes the PHP array index and key manipulation techniques. Share to everyone for your reference. Specifically as follows:
<?php
$array = Array ("A", "B", "C");//define array
$array [] = "Simon";//Add a new array element
Print_r ($array);//output array
?>
<?php
$array = Array ("A", "B", "C");//define Array
$array [9] = "Simon";//Add a new array element
Print_r ($array);//output array
?>
<?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] = m;
Print_r ($array);
Now add a key
$array ["X"] = m;
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 a key
$array [] =;
Print_r ($array);
Re-indexing using the Array_values function
$array = array_values ($array);
$array [] =;
Print_r ($array);
? >
I hope this article will help you with your PHP program design.