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.
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>';
}
精彩评论