How can I replace my array key to particular name
Array ( [0] => 0 [1] => 1 [2] => 3 [3] => 4 [4] => 5 )
How can I replace my array key to particular name
Array ( [0] => 0 [1] => 1 [2] => 3 [3] => 4 [4] => 5 )
If you're looking to replace a key based on the value, you could use this code: (assuming you want to replace Array[4])
<?php
foreach ($array as $key => $value) {
if ($value == "5") {
$array['new_key'] = $value;
unset($array[$key]));
}
}
If you want to define a specific key, you only have to say so:
<?php
$array['new_key'] = 'some_value';