Hi friends i am working on survey i need to extract an array from an array stored inside it
how to do it i am looking to extract answer array based on question id for example 13 .
i have the question id with me . answer array is associated with question .
.how to extract the question array and answer array from the main array based on the value of question id for example 13
now if i need the array which has the question id along with its associated id how to do it then from my array structure?
my code is like this
Array
(
[0] => Array
(
[que_info] => Array
(
[question_id] => 13
[description] => Overall Customer Satisfaction.
)
[answers] => Array
(
[0] => Array
(
[answer_id] => 45
[answer_text] => Very dissatisfied
)
)
)
[1] => Array
(
[que_info] => Array
(
[question_id] => 14
[description] => Progress (often referred to as Task Resolution or similar)
)
[answers] => Array
(
[0] => Array
(
[answer_id] => 52
[answer_text] => None
)
[1] => Array
(
[answer_id] => 53
[answer_text] => Very little
)
)
)
)
any help will be appreciated 🙂
First off, that’s not a 2D array, that’s an array tree. A 2D array always has an element array[x][y] for every array[x] and never any array[x][y][z].
Iterate through the array with a foreach, and return an answer list when you find an element with an id corresponding to question_id.
Example: