如何覆盖php中的指针关联?或者如何操作n维数组?
我在 php (&) 中的指针操作符上遇到了一个令人讨厌的小问题。 我想循环一个 while 循环,它将数据写入数组中。 每次它都应该写入数组的下一个维度(第一个维度是 $array,然后是 $array[0],然后是 array[0][0],等等)。 我想通过使用指针链接到 $array 来实现此目的,然后像这样更改指针:
$pointer = &array;
while($bla){
$pointer = &$pointer[0];
}
因此,每次触发 while 时,指针都会链接到 $array 的另一个维度。 但这似乎不起作用......
我真的很感谢你的帮助,谢谢。
I have a nasty little problem with the pointer opperator in php (&).
I want to loop through a while loop, which writes data in an array.
Each time it is supposed to write into the next dimension of the array (1st in $array, then in $array[0], then in array[0][0], etc).
I wanted to do this by linking to $array with a pointer, then changing the pointer like this:
$pointer = &array;
while($bla){
$pointer = &$pointer[0];
}
So everytime while is triggered the pointer links to a further dimension of $array.
That doesn't seem to work though...
I would really appretiate your help, thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试了你的代码并且它有效。测试:
首先创建数组,然后执行循环。
I tried your code and it works. Test:
This first creates the array and then does the loop.
我不确定这是否是您想要的,但您在这里。 :-)
输出:
I'm not sure if this is what you wanted, but here you are. :-)
Outputs: