0

I am new to Multi-Dimensional arrays and working on building my php skills as well. I have an associative array which I want to get the nested elements of the array but not have to worry about the multi-dem arrays name. Example:

Array ( 
[cur_wea_array] => Array ( [status] => current [day] => 0 ) 
[for_wea_array0] => Array ( [status] => current_forecast [day] => 1 ) 
[for_wea_array1] => Array ( [status] => current_forecast [day] => 2 )
[for_wea_array3] => Array ( [status] => current_forecast [day] => 3 ) )

I would like to not to have to worry about the cur_wea_array element and just loop through and get the status element. Is there a way you can loop [%wildcard][day] or something? So I can get all the status or day elements without having to specify [cur_wea_array] and [for_wea_array0]?

3 Answers 3

4
foreach ( $array as $inner_array )
{
    echo $inner_array['day']; // or $inner_array['status'];
}

This is a basic foreach example specific to your case, every time the loop iterates, $inner_array is populated with each inner array

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you I really appreciate the quick response.
1

You can just use a foreach loop:

foreach ($array as $array_element) 
{
    // your $array_element contains the inner array
}

Comments

-1

If you only want the array keys, you can access them with something like:

$array_keys = array_keys($array);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.