2

i have an array output like this :

Array
(
    [2015-01-23] => Array
        (
            [0] => Array
                (
                    [orgdate] => 2015-01-23
                    [origin] => india
                )

        [1] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => us
            )

        [2] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => england
            )

        [3] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => india2
            )

        [4] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => uae
            )

        [5] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => africa
            )

        [6] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => china
            )

        [7] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => hongkong
            )

        [8] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => africa2
            )

        [9] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => africa3
            )

        [10] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => africa4
            )

        [11] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => africa5 
            )

    )

[2015-01-14] => Array
    (
        [0] => Array
            (
                [orgdate] => 2015-01-14
                [origin] => japan1
            )

        [1] => Array
            (
                [orgdate] => 2015-01-14
                [origin] => japan2
            )

        [2] => Array
            (
                [orgdate] => 2015-01-14
                [origin] => japan3
            )

        [3] => Array
            (
                [orgdate] => 2015-01-14
                [origin] => japan4
            )

    )

[2015-01-13] => Array
    (
        [0] => Array
            (
                [orgdate] => 2015-01-13
                [origin] => russia
            )

    )

)

now i want to display 2015-01-23 , 2015-01-14 , 2015-01-13 and then each inner contents

origin: india
origin: usa
origin: england , etc....

how i accomplish this.? i already tried recursive function like this , but this couldn't find solution

any help would be greatly appreciated

3
  • your question is ambiguous..the inner array doesn't have 'origin' key at all how can you expect it to print Commented Jan 31, 2015 at 9:51
  • could you please provide an accurate example of the result you want to achieve? it's not very clear... Commented Jan 31, 2015 at 9:52
  • i edited the question, please refresh Commented Jan 31, 2015 at 9:58

2 Answers 2

3

you don't need a recursion as your array is flat (only 1 deep)

I'm not sure what you want but:

foreach($array as $key=>$subarray)
{
    echo $key;
    foreach($array[$key] as $subarray)
    {
        echo "origin".$subarray["origin"];
    }
}

this should work. If you just want to see for debug, use var_dump($array);

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

1 Comment

my comment about recursion is wrong though. You need a recursion when you don't know how deep is your array.
1

try this:

foreach($array as $innerArray){
 foreach($innerArray as $result){
echo "origin: "." ".$result['orgdate']." ".$result['origin'];
 }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.