How to Reset Array Keys in PHP?
Are you looking for example of how to reset array keys in php. you can understand a concept of php reset array keys starting 0. step by step explain php reset array keys to numeric. In this article, we will implement a reset array keys php starting from 0. Let's get started with php array_values in php example.
Here, i will give you two examples of how to reset array keys with php and how to reset keys with remove empty values using array_filter function. so let's see both example with php.
Example 1:
<?php
$myArray = [
'3' => 'Mayank',
'4' => 'Rohit',
'2' => 'Karan',
'7' => 'Himmat'
];
$myNewArray = array_values($myArray);
print_r($myNewArray);
?>
Output
Array
(
[0] => Mayank
[1] => Rohit
[2] => Karan
[3] => Himmat
)
Example 2:
<?php
$myArray = [
'3' => 'Mayank',
'4' => 'Rohit',
'2' => 'Karan',
'7' => 'Himmat',
'6' => '',
'9' => 'Kiran',
'1' => ''
];
$myNewArray = array_values(array_filter($myArray));
print_r($myNewArray);
?>
Output
Array
(
[0] => Mayank
[1] => Rohit
[2] => Karan
[3] => Himmat
[4] => Kiran
)
i hope it can help you...

Hardik Savani
I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Generate 4,6,8,10 Digit Random number in PHP?
- How to get last element of array in Javascript?
- How to set value as key in PHP array?
- How to convert array values to lowercase in PHP?
- How to convert Object into Array in PHP?
- How to get maximum key value of array in PHP?
- How to remove empty values from array in PHP?
- How to add prefix in each key of PHP Array?
- How to get minimum key value of array in PHP?
- How to remove null values from array in PHP?