S
S
Sergey Beloventsev2016-08-04 20:44:28
PHP
Sergey Beloventsev, 2016-08-04 20:44:28

Again, it is not possible to enumerate the array, explain how correctly?

here is the culprit

array(10) { 
        [0]=> array(1) { 
        	[0]=> object(stdClass)#110 (7) { 
        		["id"]=> string(5) "27741" 
        		["type"]=> string(8) "KPPeople" 
        		["nameRU"]=> string(30) "Джей Джей Абрамс" 
        		["nameEN"]=> string(11) "J.J. Abrams" 
        		["posterURL"]=> string(29) "actor_iphone/iphone_27741.jpg" 
        		["professionText"]=> string(18) "Режиссеры" 
        		["professionKey"]=> string(8) "director" }
        } 
        [1]=> array(127) { 
        	[0]=> object(stdClass)#108 (8) { 
        		["id"]=> string(7) "2196854" 
        		["type"]=> string(8) "KPPeople" 
        		["nameRU"]=> string(21) "Джон Бойега" 
        		["nameEN"]=> string(11) "John Boyega" 
        		["description"]=> string(4) "Finn" 
        		["posterURL"]=> string(31) "actor_iphone/iphone_2196854.jpg" 
        		["professionText"]=> string(12) "Актеры" 
        		["professionKey"]=> string(5) "actor" } 
        	[1]=> object(stdClass)#111 (8) { 
        		["id"]=> string(7) "3016071" 
        		["type"]=> string(8) "KPPeople" 
        		["nameRU"]=> string(21) "Дэйзи Ридли" 
        		["nameEN"]=> string(12) "Daisy Ridley" 
        		["description"]=> string(3) "Rey" 
        		["posterURL"]=> string(31) "actor_iphone/iphone_3016071.jpg" ["professionText"]=> string(12) "Актеры" 
        		["professionKey"]=> string(5) "actor" }...
        } 
        [2]=> array(14) { 
        	[0]=> object(stdClass)#237 (7) { 
        		["id"]=> string(5) "27741" 
        		["type"]=> string(8) "KPPeople" 
        		["nameRU"]=> string(30) "Джей Джей Абрамс" 
        		["nameEN"]=> string(11) "J.J. Abrams" 
        		...} 
        [3]=> array(1) { 
        	[0]=> object(stdClass)#251 (7) {
        		["id"]=> string(7) "2469864" 
        		["type"]=> string(8) "KPPeople" 
        		["nameRU"]=> string(33) "Георгий Даниелянц" 
        		["nameEN"]=> string(0) "" 
        		["posterURL"]=> string(31) "actor_iphone/iphone_2469864.jpg" ["professionText"]=> string(33) "Режиссеры дубляжа" 
        		["professionKey"]=> string(14) "voice_director" 
        	} 
        }...

I need to get id, nameRU, posterURL and professionKey and the number of arrays of the first level and the second, as you can see, can be from 0 to infinity

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
SharuPoNemnogu, 2016-08-04
@Sergalas

forech ($array as $items) {
    foreach($items as $object) {
        /* последний уровень объект, а не массив
        тут уже доступны ваши свойства, следующим образом.
        $object->id
        $object->nameRU
        $object->posterURL
        $object->professionKey
        */
    }
}

X
xmoonlight, 2016-08-04
@xmoonlight

if(is_object($item)) $item=(array)$item;

P
Pavel Tuzov, 2016-08-04
@PavelTuzov

$result =array();
if (count($array)) {
    foreach ($array as  $lv1) {
        foreach ($v as $lv2) {
            $result[] = array(
                'id' => $lv2['id'],
                'nameRu' => $lv2['nameRu'],
                'posterURL' => $lv2['posterURL'],
                'professionKey' => $lv2['professionKey'],
            );
        }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question