03-Apr-2023
.
Admin
Hi Dev,
There is not just one way to solve a problem, there are many different ways that can be tried. php remove array numeric index from array, we will go over the remaining potential solutions.
There are example to check if how to remove array numeric index in php. in this example, we will use to unset() and array_values() function to check if how to remove array numeric index in php. so let's the following example with output.
Example 1:
index.php
<?php
$arr1 = array(
'Nice',
'for',
'Nice'
);
// remove item at index 1 which is 'for'
echo "<pre>";
unset($arr1[1]);
echo "</pre>";
// Print modified array
echo "<pre>";
var_dump($arr1);
echo "</pre>";
// Re-index the array elements
$arr2 = array_values($arr1);
// Print re-indexed array
echo "<pre>";
var_dump($arr2);
echo "</pre>";
?>
Output:
array(2) {
[0]=>
string(4) "Nice"
[2]=>
string(4) "Nice"
}
array(2) {
[0]=>
string(4) "Nice"
[2]=>
string(4) "Nice"
}
I hope it could help you...
#PHP