[英]PHP memory limit on line running foreach
Is there a more efficient way to set JSON array values than this? 有没有比这更有效的方法来设置JSON数组值?
for($i=0;$i<sizeOf($json['activity']);$i++){
$json['activity'][$i]['active'] = 'false';
}
I want to set all sub keys named 'active' to 'false' The arrays are not huge, they are multi-dimension with about 8-10 sub arrays and I am running on XAMPP localhost. 我想将所有名为“ active”的子键设置为“ false”。数组不是很大,它们是多维的,大约有8-10个子数组,并且我在XAMPP localhost上运行。
I am getting 我正进入(状态
Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes)
error briefly and then the rest of the code runs OK on a setInterval. 错误短暂地出现,然后其余代码在setInterval上运行正常。 I have looked at ways to set the memory limit but suspect there must be a cleaner way to set the array keys.
我研究过设置内存限制的方法,但怀疑必须有一种更干净的方法来设置阵列键。
Thank you 谢谢
If I understand this correctly, you created an infinite loop since everytime it runs, your array gets one more value, same as your $i-counter. 如果我正确理解这一点,那么您就创建了一个无限循环,因为每次循环运行时,您的数组都会获得一个与$ i-counter相同的值。 Try getting the count of the array first in a seperate variable and then run the loop with that
尝试首先在单独的变量中获取数组的计数,然后使用该变量运行循环
$c = sizeOf($json['activity']); for($i=0;$i<$c;$i++){
$json['activity'][$i]['active'] = 'false';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.