请参阅下面的示例以了解这个想法:
$arr = array
(
0 => array (
$this => 3, // instead 0 => 3,
'name' => 'three',
),
1 => array (
$this => 5, // instead 0 => 5,
'name' => 'five',
),
2 => array (
$this => 7, // instead 0 => 7,
'name' => 'seven',
),
);
对于每个索引都有一个二维数组。但是为了调用$ arr [0] [0],转而调用$ arr [0]。这些虚构的想法与想要的结果相呼应。
echo $arr[0]; // printing 3
echo $arr[0]['name']; // printing 'three'
echo $arr[0][0]; // printing 3 (not relevant)
有类似的东西吗?
答案 0 :(得分:2)
在PHP 5中,您可以扩展ArrayObject以使其成为类似于数组的对象。你可以覆盖它的一些行为
-Xmx20480M
-XX:PermSize=128M
-XX:MaxPermSize=256M
-XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled
-Xms20480M
-XX:NewSize=10240M
-XX:SurvivorRatio=4
-XX:+UseCompressedOops
-XX:CMSInitiatingOccupancyFraction=60
-XX:+UseStringCache
-XX:+UseFastAccessorMethods
-XX:ErrorFile=c:/hs_err.log
-XX:HeapDumpPath=c:/
-XX:+HeapDumpOnOutOfMemoryError
-Xrs
答案 1 :(得分:0)
您正在尝试访问多维数组的元素
<?php
$marks = array(
"m" => array
(
"physics" => 35,
"maths" => 30,
"chemistry" => 39
),
"q" => array
(
"physics" => 30,
"maths" => 32,
"chemistry" => 29
),
"z" => array
(
"physics" => 31,
"maths" => 22,
"chemistry" => 39
)
);
/* Accessing multi-dimensional array values */
echo "Marks for m in physics : " ;
echo $marks['m']['physics'] . "<br />";
echo "Marks for q in maths : ";
echo $marks['q']['maths'] . "<br />";
echo "Marks for z in chemistry : " ;
echo $marks['z']['chemistry'] . "<br />";
?>
这将产生
Marks for m in physics : 35
Marks for q in maths : 32
Marks for z in chemistry : 39
现在你的问题是通过调用$ arr [0]来返回$ arr [0] [0]的值,因为@icecub说'然后这可以通过
来完成reset()函数用于将数组的内部指针移动到第一个元素。LINK