@aleps

Как правильно получить значение из нескольких многомерных массивов?

Как правильно получить нужные значение из нескольких многомерных массива такого вида

Array
(
    [serial] => Array
        (
            [title_ru] => Новенькая
            [title_en] => New Girl
            [token] => 0
            [type] => serial
            [kinopoisk_id] => 581129
            [world_art_id] => 
            [translator] => Paramount Comedy
            [translator_id] => 90
            [iframe_url] => 0
            [seasons_count] => 3
            [episodes_count] => 60
            [category] => 
            [block] => Array
                (
                    [blocked_at] => 
                    [block_ru] => 
                    [block_ua] => 
                )

            [last_episode_time] => 2017-07-09 14:42:02
        )

    [season_episodes_count] => Array
        (
            [0] => Array
                (
                    [season_number] => 3
                    [episodes_count] => 11
                    [episodes] => Array
                        (
                            [0] => 1
                            [1] => 2
                            [2] => 3
                            [3] => 4
                            [4] => 5
                            [5] => 6
                            [6] => 7
                            [7] => 8
                            [8] => 9
                            [9] => 10
                            [10] => 11
                        )

                )

            [1] => Array
                (
                    [season_number] => 1
                    [episodes_count] => 24
                    [episodes] => Array
                        (
                            [0] => 1
                            [1] => 2
                            [2] => 3
                            [3] => 4
                            [4] => 5
                            [5] => 6
                            [6] => 7
                            [7] => 8
                            [8] => 9
                            [9] => 10
                            [10] => 11
                            [11] => 12
                            [12] => 13
                            [13] => 14
                            [14] => 15
                            [15] => 16
                            [16] => 17
                            [17] => 18
                            [18] => 19
                            [19] => 20
                            [20] => 21
                            [21] => 22
                            [22] => 23
                            [23] => 24
                        )

                )

            [2] => Array
                (
                    [season_number] => 2
                    [episodes_count] => 25
                    [episodes] => Array
                        (
                            [0] => 1
                            [1] => 2
                            [2] => 3
                            [3] => 4
                            [4] => 5
                            [5] => 6
                            [6] => 7
                            [7] => 8
                            [8] => 9
                            [9] => 10
                            [10] => 11
                            [11] => 12
                            [12] => 13
                            [13] => 14
                            [14] => 15
                            [15] => 16
                            [16] => 17
                            [17] => 18
                            [18] => 19
                            [19] => 20
                            [20] => 21
                            [21] => 22
                            [22] => 23
                            [23] => 24
                            [24] => 25
                        )

                )

        )

)

Array
(
    [serial] => Array
        (
            [title_ru] => Новенькая
            [title_en] => New Girl
            [token] => 0
            [type] => serial
            [kinopoisk_id] => 581129
            [world_art_id] => 
            [translator] => Sunshine Studio
            [translator_id] => 93
            [iframe_url] => 0
            [seasons_count] => 1
            [episodes_count] => 22
            [category] => 
            [block] => Array
                (
                    [blocked_at] => 
                    [block_ru] => 
                    [block_ua] => 
                )

            [last_episode_time] => 2017-04-05 16:56:42
        )

    [season_episodes_count] => Array
        (
            [0] => Array
                (
                    [season_number] => 6
                    [episodes_count] => 22
                    [episodes] => Array
                        (
                            [0] => 1
                            [1] => 2
                            [2] => 3
                            [3] => 4
                            [4] => 5
                            [5] => 6
                            [6] => 7
                            [7] => 8
                            [8] => 9
                            [9] => 10
                            [10] => 11
                            [11] => 12
                            [12] => 13
                            [13] => 14
                            [14] => 15
                            [15] => 16
                            [16] => 17
                            [17] => 18
                            [18] => 19
                            [19] => 20
                            [20] => 21
                            [21] => 22
                        )

                )

        )

)


с каждого из "родительских" массивов хочу получить значение:
season_number
episodes_count
и перечисление episodes

помогите хоть направлением мысли, как лучше и правильнее это сделать
spoiler
php учу, перебирал циклом foreach, но что-то не совсем выходит вывести так как хочу
  • Вопрос задан
  • 188 просмотров
Пригласить эксперта
Ответы на вопрос 1
Exploding
@Exploding
wtf?
array_walk_recursive
вот пример с php.net:
$sweet = array('a' => 'apple', 'b' => 'banana');
$fruits = array('sweet' => $sweet, 'sour' => 'lemon');

function test_print($item, $key)
{
    echo "$key holds $item\n";
}

array_walk_recursive($fruits, 'test_print');


Вот еще в закромах нашел, можно приспособить под вашу задачу
// рекуксивный обход массива $array и удаление элемента с КЛЮЧЕМ(ключами) $value
function removeArrElemByKey( &$array, $value ){ 
	if(count($array) > 1)
		foreach( $array as $key => $val ){
			if( is_array($val) ){
				removeArrElemByKey($array[$key], $value);
			} elseif( $val===$value ){
				unset($array[$key]);
			}
		}
}
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы