php obtiene extraer algunos valores de una matriz multidimensional
Frecuentes
Visto 370 veces
-2
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
4 Respuestas
1
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
1
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
1
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
1
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 php arrays multidimensional-array or haz tu propia pregunta.
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. - Mitya
A fancy way to do it is writing a recursive function to perfrom the search. - thedethfox