PHP 多维数组 - 创建和读取数据
我对多维数组有一个小问题。我觉得他们和JAVA里的不一样。例如;我创建了一个类似这样的数组;
$myArray = array();
然后我尝试为其分配 4 个不同的数组,如下所示。
$myArray[0] = $newArray0;
$myArray[1] = $newArray1;
$myArray[2] = $newArray2;
$myArray[3] = $newArray3;
但是,当我尝试从以下行的单元格中读取数据时,
$myArray[0][2];
我无法获得我想要的数据。你们能告诉我我哪里错了吗?
多谢!
I have a little problem with multidimensional arrays. I think they are not like those in JAVA. For instance; I have created a array something like this;
$myArray = array();
Then I try to assign 4 different arrays to it as following.
$myArray[0] = $newArray0;
$myArray[1] = $newArray1;
$myArray[2] = $newArray2;
$myArray[3] = $newArray3;
But when I try to read a data from a cell with following line,
$myArray[0][2];
I could not get the data what I was hoping for. Can you guys tell me where am I mistaken?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试执行的操作应该有效,请尝试确保 $newArray0 也是数字数组而不是关联数组。您可以使用以下代码了解如何设置数组:
如果您以正确的方式完成了操作,则输出必须类似于:
如果这就是它所说的,那么 $myArray[0][2] 应该说'ETC'。
What you're trying to do should work, try to make sure that $newArray0 is also a numeric array and not an associative array. You can find out how your array is being setup with the following code:
If you've done it the right way, the output must be something similar to:
If that's what it says, then $myArray[0][2] should say 'Etc'.
你的想法是正确的
工作演示
you got the right idea
WORKING DEMO