0
[
{
    "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”。

4

2 回答 2

2

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

然后你可以这样做:

<select>
foreach($array as $a)
{
    echo "<option value='".$a['youemail']."'";
}
</select>
于 2013-09-19T09:26:30.393 回答
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>";
?> 
于 2013-09-19T09:32:07.630 回答