php - Get all stored ID's from the array

**
I have an array which stores all ID's of episodes depending on tv show and amount of seasons. Each series has a different number of seasons.
And I need an Idea how to get all ID's from$seasons[]['episodes']
no matter how many seasons it has.
I want it to returns to me all the ID of the episodes from the array.**
Array (
[0] => Array (
[name] => Season 1
[image_id] => 2119
[episodes] => Array (
[0] => 2122
[1] => 2123
[2] => 2124
[3] => 2125
[4] => 2126
)
[year] => 2017
[description] => Atypical is a coming-of-age television series created by Robia Rashid for Netflix. It focuses on the life of 18-year-old Sam Gardner (Keir Gilchrist), who is on the autism spectrum. The first season was released on August 11, 2017, consisting of eight episodes.
[position] => 0
)
[1] => Array (
[name] => Season 2
[image_id] => 2120
[episodes] => Array (
[0] => 2127
[1] => 2128
[2] => 2129
[3] => 2130
[4] => 2131
)
[year] => 2018
[description] => The ten-episode second season was released on September 7, 2018. In October 2018, the series was renewed for a third season of ten episodes.
[position] => 0
)
)
Answer
Solution:
You are looking forarray_column
function.
<?php
$results = array_column($seasons, 'episodes'); // this will return 2d array of arrays with 'episodes'
$final_results = call_user_func_array('array_merge', $results); // this will make 1d array of 2d array
print_r($final_results);
?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to a member function getclientoriginalname() on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.