php reset array keys – 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.

Reset keys of array elements using PHP

The array_values() function returns an array containing all the values of an array. and read this example Php Array Remove Keys Keep Values

php reset array keys
php reset array keys

Example 1: php reset array keys
To reset keys of array elements using PHP, the source code is as follows−

<?php
  
    $websites = [
            '3' => 'tamilblastres',
            '4' => 'hdhub4u',
            '2' => 'tamilmv',
            '7' => 'moviszap'
        ];
  
    $finalOutputArr = array_values($websites);
  
    print_r($finalOutputArr);
  
?>

Result

Array
 (
     [0] => tamilblastres
     [1] => hdhub4u
     [2] => tamilmv
     [3] => moviszap
 )

Example 2: Reset keys of array elements using PHP

<?php
  
    $websites = [
            '3' => 'tamilblastres',
            '4' => 'hdhub4u',
            '2' => 'tamilmv',
            '7' => 'moviszap',
            '6' => '',
            '9' => 'Bolly4u',
            '1' => ''
        ];
  
    $finalOutputArr = array_values(array_filter($websites));
  
    print_r($finalOutputArr);
  
?>

Free Live Chat for Any Issue

Result

Array
 (
     [0] => tamilblastres
     [1] => hdhub4u
     [2] => tamilmv
     [3] => moviszap
     [4] => Bolly4u
 )

5/5 - (12 votes)