JustPaste.it

How to Reset Array Keys in PHP?

php reset array keys : using array_values – It returns an indexed array of values from the associative array.

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.

  
    $myArray = [
            '3' => 'Mayank',
            '4' => 'Rohit',
            '2' => 'Karan',
            '7' => 'Himmat',
            '6' => '',
            '9' => 'Kiran',
            '1' => ''
        ];
  
    $myNewArray = array_values(array_filter($myArray));
  
    print_r($myNewArray);
 
Example :

Php Reset Array Keys