Navigazione di oggetti e matrici

Puoi per favore mostrarmi un esempio in php su come get informazioni specifiche in un ciclo di qualche tipo, voglio accedere a [language] e [answer] => [question] => each volta che è lì. Grazie

 Array ( [0] => stdClass Object ( [type] => text [cue] => stdClass Object ( [type] => text [text] => pri [sound] => [language] => eo [part_of_speech] => Preposition ) [responses] => Array ( [0] => stdClass Object ( [type] => meaning [text] => about, concerning [language] => en [quizzes] => Array ( [0] => stdClass Object ( [type] => multiple_choice [answer] => pri [question] => about, concerning ) ) ) ) [author] => stdClass Object ( [profile] => stdClass Object ( [name] => Tomo [profile_url] => http://smart.fm/users/yubizume [icon_url] => http://assets2.smart.fm/assets/users/yubizume/e1b0e7f8_medium.jpg ) [username] => yubizume ) [language] => eo [dc_creator] => yubizume [href] => http://smart.fm/items/830187 [id] => 830187 ) [1] => stdClass Object ( [type] => text [cue] => stdClass Object ( [type] => text [text] => pri [sound] => [language] => eo [part_of_speech] => Preposition ) [responses] => Array ( [0] => stdClass Object ( [type] => meaning [text] => about, concerning (prep) [sound] => http://assets0.smart.fm/assets/generated_sounds/2009111923/a857356fb588022411fa21371a96e494.mp3 [language] => en [quizzes] => Array ( [0] => stdClass Object ( [type] => multiple_choice [answer] => pri [question] => about, concerning (prep) ) ) ) ) [author] => stdClass Object ( [profile] => stdClass Object ( [name] => AriadneAranea [profile_url] => http://smart.fm/users/AriadneAranea [icon_url] => http://a1.twimg.com/profile_images/489977042/2009-01_-_New_Year_at_Slimbridge_02_bigger.jpg ) [username] => AriadneAranea ) [language] => eo [dc_creator] => AriadneAranea [href] => http://smart.fm/items/1773996 [id] => 1773996 ) 

 // $objects is the arrays with all those objects foreach($objects as $object) { echo $object->cue->language; // language foreach($object->responses as $response) { // if there are no quizzes, we skip the part below // we skip it because $object->quizzes will produce a warning or a notice // if "quizzes" is not a present in the $object if(!isset($object->quizzes)) { continue; } // quizess foreach($response->quizzes as $quiz) { echo $quiz->question; // question echo $quiz->answer; // answer } } } 

Vuoi qualcosa di lke questo:

 <?php foreach($foo as $i){ echo 'Language (cue): ' . $i['cue']['language'] . "\n"; foreach($i['responses'] as $j){ echo 'Language (response): ' . $j['language'] . "\n"; foreach($j['quizzes'] as $k){ echo 'Answer: ' . $k['answer'] . "\n"; echo 'Question: ' . $k['question'] . "\n"; } } } ?> 

Due osservazioni:

(1) Ho suggerito di usare var_export () per generare un campione di copia e incolla per testarlo ma apparentemente stdClass :: __ set_state () non può essere letto facilmente . Scusa se indico qualcuno.

(2) Non è difficile da build da soli se lo fai passo dopo passo.

 <?php // First foreach($foo as $c => $v){ var_dump($c, $v); exit; } // Second foreach($foo as $i){ echo 'Language (cue): ' . $i['cue']['language'] . "\n"; foreach($i['responses'] as $c => $v){ var_dump($c, $v); exit; } } // Etc. ?>