php 中的解析器错误?无法嵌套数组索引(访问数组中的值以查找另一个数组)而不需要额外的代码
while($assocArray = mysql_fetch_assoc($result))
{
for ($j = 0; $j < $length; $j++)
{
$column = $fields[$j]; // + works
echo "$assocArray[$column] "; // +
//echo "$assocArray[ $fields[$j] ] "; // - doesn't work, should be same
}
echo "<br/>";
}
数值数组也报告了类似的问题,据说已经解决了。我正在使用一个非常新的 PHP 版本(5.3.6),所以它一定是一个单独的错误。生成解析错误。
while($assocArray = mysql_fetch_assoc($result))
{
for ($j = 0; $j < $length; $j++)
{
$column = $fields[$j]; // + works
echo "$assocArray[$column] "; // +
//echo "$assocArray[ $fields[$j] ] "; // - doesn't work, should be same
}
echo "<br/>";
}
A similar problem was reported for numeric arrays, which supposedly was solved. I'm using a very new build of PHP (5.3.6) so it must be a separate bug. Generates parse error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
注意其中额外的
{}
。 PHP 的解析器通常“不贪婪”,并且会比大多数其他脚本语言更早地停止解析变量。这在多维数组上尤其明显:Try this:
Note the extra
{}
in there. PHP's parser is generally "not greedy" and will stop parsing variables much earlier than most other scripting languages. It's especially evident on multi-dimensional arrays:用花括号包围整个表达式:
仅供参考:这部分是一个品味问题,但就我个人而言,我更喜欢内联数组,尤其是嵌套数组。这不是更好吗?
Surround the whole expression with curly braces:
FYI: This is partially a matter of taste, but personally, I prefer not inlining arrays, especially with nested arrays. Isn't this nicer?
如果您确实需要尾随空格,请附加类似的内容
If you really need the trailing whitespace, append something like