php obtiene extraer algunos valores de una matriz multidimensional

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] => holmesbilly79@yahoo.com
            [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] => vaguy83_2008@yahoo.com
            [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

preguntado el 24 de agosto de 12 a las 09:08

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. -

A fancy way to do it is writing a recursive function to perfrom the search. -

4 Respuestas

Prueba esto:

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'];
        }
    }
}

Respondido 24 ago 12, 10:08

Have you tried nested foreach loops? I.e

foreach($arrays as $array)
 {
      foreach($array as $rows)
       {
         #print your rows here etc
       }
 }

Respondido 24 ago 12, 10:08

simple, follow arrays

$array['entry'][0]['email']

Respondido 24 ago 12, 10:08

i want this by loop, there are around 5000 of items :) - Suneth Kalhara

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

Respondido 24 ago 12, 10:08

i tried using foreach foreach($result1 as $rs=>$sr){ print_r($sr['id']); } no luck - Suneth Kalhara

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.