[英]how to access 2d array values?
do you have any idea why the "echo" in the following loop doesn't work? 你知道为什么以下循环中的“echo”不起作用吗?
while( $nl = mysql_fetch_array($Lresult) )
{
$clkword[$i] = $nl['Word'];
$relatedlinks[$i] = array(
$i => array(
"CWord" => $nl['Word'],
"RLinks" => $nl['Link_Add']
)
);
echo $relatedlinks[$i]['CWord'];
$i++;
}
Because the way you've set it up, $relatedlinks[$i]
is an array containing (at the key $i
) an array containing keys "CWord"
and "RLinks"
. 因为你设置它的方式,
$relatedlinks[$i]
是一个数组,包含(在键$i
)一个包含键"CWord"
和"RLinks"
的数组。 In other words, you have an array inside an array inside an array, whereas what you wanted was an array inside an array. 换句话说,在数组内的数组中有一个数组,而你想要的是数组中的数组。 Change the line
改变线
$relatedlinks[$i]=array($i => array("CWord" => $nl['Word'],
"RLinks" => $nl['Link_Add']));
to read 读书
$relatedlinks[$i] = array( "CWord" => $nl['Word'],
"RLinks" => $nl['Link_Add']
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.