up vote 0 down vote favorite
share [fb]

I have an array within an array within an array and so on:

array(3) {
    [0]=> array(1) {
        ["weather"]=> array(2) {
            ["ID"]=> string(1) "1"
            ["weather_types"]=> string(5) "Clear"
        }
    }
    [1]=> array(1) {
        ["weather"]=> array(2) {
            ["ID"]=> string(1) "2"
            ["weather_types"]=> string(6) "Clouds"
        }
    }
    [2]=> array(1) {
        ["weather"]=> array(2) {
            ["ID"]=> string(1) "3"
            ["weather_types"]=> string(4) "Rain"
        }
    }
} 

I will assign as a variable, let's use: $select_item

and then have the weather_types strings, "Clear", "Cloudy", and "Rain" w/o quotes be the only data that appears in my select/option list.

I need to somehow remove all the other array data so that "Clear", "Cloudy", and "Rain" is left.

then I will save the selected option to the database table.

link|improve this question

75% accept rate
also will use foreach loop to populate the select option list. – sloga May 26 at 21:49
and what did you tried? Looks like you want to somebody did this work for you. – OZ_ May 26 at 22:03
feedback

1 Answer

up vote 0 down vote accepted

Assuming $weather is the array and you want the value attribute to contain ID. Either way, adjusting the following to your needs should be trivial.

foreach ($weather as $select_item) {
  echo '<option value="', $select_item['weather']['ID'], '">', $select_item['weather']['weather_types'], '</option>';
}
link|improve this answer
Perfect! Thanks – sloga May 26 at 22:24
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.