-2

I want to know how to change the key values of an array using PHP

Input array :

Array ( [2] => one [3] => Array [5] => two [6] => three [8] => four )

I want output like given below,

Array ( [0] => one [1] => Array [2] => two [3] => three [4] => four )

Please anyone help..

KMS
  • 567
  • 3
  • 15

1 Answers1

1

You have to use array_values() for this.

$a = array(
    10 => "a",
    20 => "b",
    30 => "c"
);
$b = array_values($a);
print_r($b);

This will be the output.

Array
(
    [0] => a
    [1] => b
    [2] => c
)

Here is the demo.

Niranjan N Raju
  • 11,924
  • 3
  • 21
  • 41