我有这个数组
<?php
$themename = "So";
$shortname = "se";
$options = array (
array( "name" => "the_firstname",
"desc" => "The firstname of a person",
"id" => $shortname."_the_firstname",
"type" => "text",
"value" => ""),
array( "name" => "the_lastname",
"desc" => "A persons lastname",
"id" => $shortname."_the_lastname",
"type" => "text",
"value" => ""),
);
foreach($options as $key => $value)
{
echo $value['id']."<br/>";
}
?>
使用类似的键,例如id
键。我想访问第一个数组的id
值。
执行此操作echo $value['id'][0]."<br/>";
或echo $options['id'][0]."<br/>";
没有帮助。
如何显示第一个id
的价值?
答案 0 :(得分:2)
echo $options[0]['id'];
应该在for
循环内的顶层执行此操作:$value['id']
。这里不需要[0]
,因为$value
包含$options
数组中的第一个(0)元素。