1

I have an array like:

Array
(
    [6] => Array
        (
            [quantity] => 23
            [orgId] => 6
            [validity] => 20
        )

    [2] => Array
        (
            [quantity] => 5
            [orgId] => 2
            [validity] => 2
        )

    [5] => Array
        (
            [quantity] => 5
            [orgId] => 5
            [validity] => 4
        )

    [4] => Array
        (
            [quantity] => 7
            [orgId] => 4
            [validity] => 10
        )

)

and i want to show that like this:

Array
(
    [0] => Array
        (
            [quantity] => 23
            [orgId] => 6
            [validity] => 20
        )

    [1] => Array
        (
            [quantity] => 5
            [orgId] => 2
            [validity] => 2
        )

    [2] => Array
        (
            [quantity] => 5
            [orgId] => 5
            [validity] => 4
        )

    [3] => Array
        (
            [quantity] => 7
            [orgId] => 4
            [validity] => 10
        )

)

To do that i used array_push & some other technique but fail. can someone help me thanks.

0

2 Answers 2

8

From your example you want the elements to be re-indexed, and maintain their existing order.

Try using array_values().

array_values() returns all the values from the input array and indexes numerically the array.

Sign up to request clarification or add additional context in comments.

Comments

0

yes array_values is the answer, you can go through this discussion too http://www.codingforums.com/archive/index.php/t-17794.html

1 Comment

deadlink in this answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.