Jus*_*man 5 php multidimensional-array
我一直在努力弄清楚为什么我的阵列没有按预期工作.我在函数上使用的代码与下面的代码相同,但它在我的程序中默默地失败了,所以我使用相同类型的数据和语法编写了一个独立的测试用例,并得到了关于非法偏移类型的错误.
Warning: Illegal offset type in <file location>\example.php on line 12
Warning: Illegal offset type in <file location>\example.php on line 16
Run Code Online (Sandbox Code Playgroud)
这些引用了两行,其中特别提到了"$ questions [$ question]".
<?php
$questions = array(
"???:??"=>array("??","??"),
"???:??"=>array("??","??","??","???","???","??"),
);
$question = $questions["???:??"];
if (is_array($questions[$question])){
$res = $questions[$question][0];
} else {
$res = $questions[$question];
}
echo $res;
?>
Run Code Online (Sandbox Code Playgroud)
我想我在这里超出了我的技能水平,因为虽然我可以看到http://php.net/manual/en/language.types.array.php上的警告,其中指出"数组和对象不能用作这样做会导致警告:非法的偏移类型." ,我无法看到我正在做的与该页面上的示例#7有什么不同.
我非常感谢能够帮助我理解并解决我的问题的解释.
先感谢您!