Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a multidimensional array which has 2-3 levels so i need to extract some data from this array i tried with many methods but i couldn't work it

here is array which has 2 user details

Array (
    [success] => 1
    [anchor] => Bc-kqkaweL94QMZsAUZWpfAuzZakev32
    [firstPage] => 1
    [lastPage] =>
    [entry] => Array (
        [0] => Array (
            [id] => 6518718:User:10097
            [author] => 0aiffjmq4vwke
            [createdDate] => 2012-08-24T00:06:10.851Z
            [email] => [email protected]
            [fullName] => Billy Ray Holmes
            [gender] => m
            [birthdate] => 1975-06-17
            [state] => member
            [isOwner] =>
            [isAdmin] =>
            [isMember] => 1
            [isBlocked] =>
            [location] => Shreveport, LA, US, 71108
            [profileQuestions] => Array (
                [0] => Array (
                    [question] => q4
                    [answer] => Array (
                        [question] => Dating
                        [type] => select
                        [choices] => Yes,No
                        [answer] => Yes
                        [private] =>
                    )
                )
            )
        )
        [1] => Array (
            [id] => 6518718:User:10095
            [author] => 3oz2jdmjyocth
            [createdDate] => 2012-08-23T23:43:40.865Z
            [email] => [email protected]
            [fullName] => Thomas
            [gender] => m
            [birthdate] => 1983-06-20
            [state] => member
            [isOwner] =>
            [isAdmin] =>
            [isMember] => 1
            [isBlocked] =>
            [location] => US
            [profileQuestions] => Array (
                [0] => Array (
                    [question] => q4
                    [answer] => Array (
                        [question] => Dating
                        [type] => select
                        [choices] => Yes,No
                        [answer] => Yes
                        [private] =>
                    )
                )
            )
        )
    )
    [resources] => Array (
        [3oz2jdmjyocth] => Array (
            [fullName] => Thomas
            [url] => http://MyChatterBook.ning.com/profile/Thomas
        )
        [0aiffjmq4vwke] => Array (
            [fullName] => Billy Ray Holmes
            [url] => http://MyChatterBook.ning.com/profile/BillyRayHolmes
        )
    )
) 

from this array i need to get email address fullname dating answer ,.. fields can anyone know how to do this using php thanks again

share|improve this question
1  
That's really awkward for anyone to read. Help us to help you by formatting the array on multiple lines, indented, so we can see the data structure. – Utkanos Aug 24 '12 at 8:59
sorry for it.... – Suneth Kalhara Aug 24 '12 at 9:10
A fancy way to do it is writing a recursive function to perfrom the search. – thedethfox Aug 24 '12 at 9:35

4 Answers

up vote 1 down vote accepted

Try this:

foreach( $result['entry'] as $entry ) {
    echo $entry['fullName'];
    echo $entry['email'];
    foreach( $entry['profileQuestions'] as $question ) {
        if( $question['answer']['question'] == 'Dating' ) {
            echo $question['answer']['answer'];
        }
    }
}
share|improve this answer
working nicely, thanks a lot :) – Suneth Kalhara Aug 24 '12 at 10:26

Have you tried nested foreach loops? I.e

foreach($arrays as $array)
 {
      foreach($array as $rows)
       {
         #print your rows here etc
       }
 }
share|improve this answer

simple, follow arrays

$array['entry'][0]['email']
share|improve this answer
i want this by loop, there are around 5000 of items :) – Suneth Kalhara Aug 24 '12 at 9:09
what do you want to do with them ? – Mihai Iorga Aug 24 '12 at 9:15
show a list of users with there email,image,name,dating... – Suneth Kalhara Aug 24 '12 at 10:21

What have you tried? Have you tried $data[0][email] to extract the email? Can you please provide a script snipper of how you are trying to access this data from inside the array? Thanks

share|improve this answer
i tried using foreach foreach($result1 as $rs=>$sr){ print_r($sr['id']); } no luck – Suneth Kalhara Aug 24 '12 at 9:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.