Reset PHP Array Index

Use array_keys() function get keys of an array and array_values() function to get values of an array.

You want to get values of an array:

$array = array( 3 => "Hello", 7 => "Moo", 45 => "America" );

$arrayValues = array_values($array);// returns all values with indexes
echo '<pre>';
print_r($arrayValues);
echo '</pre>';

Output:

Array
(
    [0] => Hello
    [1] => Moo
    [2] => America
)

You want to get keys of an array:

$arrayKeys = array_keys($array);// returns all keys with indexes
    echo '<pre>';
    print_r($arrayKeys);
    echo '</pre>';

Output:

Array
(
    [0] => 3
    [1] => 7
    [2] => 45
)

The array_values() function [docs] does that:

$a = array(
    3 => "Hello",
    7 => "Moo",
    45 => "America"
);
$b = array_values($a);
print_r($b);
Array
(
    [0] => Hello
    [1] => Moo
    [2] => America
)

Tags:

Php

Arrays