如何在下拉列表中获取数组值。?

时间:2013-09-19 09:20:46

标签: php json

[
{
    "youname": "a",
    "youemail": "xyz@gmail.com",
    "studies": "elementary school",
    "civilstate": "single"
},
{
    "youname": "b",
    "youemail": "abcd@gmail.com",
    "studies": "secondary school",
    "civilstate": "single"
}
]

这是我的.json文件..!我解码它和json_decode并将其转换为数组格式如下..

Array ( [0] => Array ( [youname] => a [youemail] => xyz@gmail.com [studies] => elementary school [civilstate] => single )
 [1] => Array ( [youname] => b [youemail] => abcd@gmail.com[studies] => secondary school [civilstate] => single )) 

有人可以告诉我如何使用PHP在下拉列表中使用'Youemail'。

2 个答案:

答案 0 :(得分:2)

如果它在数组中,请使用$array =然后使用数组。

然后你可以这样做:

<select>
foreach($array as $a)
{
    echo "<option value='".$a['youemail']."'";
}
</select>

答案 1 :(得分:0)

使用:

<?php 
$array = array ( 
    "0" => array(
        "youname" => "a", 
        "youemail" => "xyz@gmail.com", 
        "studies" => "elementary school", 
        "civilstate" => "single" 
    ),
    "1" => array( 
        "youname" => "b", 
        "youemail" => "abcd@gmail.com",
        "studies" => "secondary school", 
        "civilstate" => "single" 
    )
);

echo "<select>";
foreach($array as $each)
{
    echo "<option value='".$each['youemail']."'>".$each['youemail']."</option>";
}
echo "</select>";
?>