1

I want to change the index of an array after doing some operations My actual output is

Array
(
    [0] => Array
        (
            [0] => 4
            [1] => 6
        )

    [2] => Array
        (
            [0] => 1
            [1] => 7
        )
    [5] => Array
       (
            [0] => 1
            [1] => 7
        )

)

I want to be something like this

Array
(
    [0] => Array
        (
            [0] => 4
            [1] => 6
        )

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

)

How to achieve this in php???? Thanks in advance

1

3 Answers 3

4

Extract only the values to a new array and the keys will be indexed from 0:

$array = array_values($array);
Sign up to request clarification or add additional context in comments.

1 Comment

I've been searching this for days. THANK YOU.
2

The array_values() function returns only values from array.

Thus, resetting all the array keys to numeric starting from 0, 1, 2, ...

You can do it using

$array = array_values($array);

http://php.net/manual/en/function.array-values.php

Comments

0

you can use the "array_values" Function for that. Please refer this link http://www.php.net/manual/en/language.types.array.php

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.