Php 其中';什么是循环?
我有以下代码:Php 其中';什么是循环?,php,arrays,loops,Php,Arrays,Loops,我有以下代码: function filterVencimientos ($arrayFull) { $filtered = array_filter($arrayFull, 'month'); var_dump($filtered); return $filtered; } function month ($var) { $response = false; if (is_array($var)) { foreach ($var as
function filterVencimientos ($arrayFull) {
$filtered = array_filter($arrayFull, 'month');
var_dump($filtered);
return $filtered;
}
function month ($var) {
$response = false;
if (is_array($var)) {
foreach ($var as $item) {
$response = month($var);
}
} else {
$date = date('Y-m');
$response = (stripos($var, $date) !== false);
}
return $response;
}
function getFiltered () {
$arrayFull = getVencimientosPorPerfil();
$arrayFiltered = filterVencimientos($arrayFull);
return $arrayFiltered;
}
然后返回这个:
Fatal error: Out of memory (allocated 4194304) (tried to allocate 262144 bytes) in C:\xampp\htdocs\app\miramonteapp\api\yscript.php on line 244
我正在尝试遍历此数组:
array(1) {
[258]=>
array(9) {
["recaudacion"]=>
array(13) {
[0]=>
string(10) "2017-01-07"
[1]=>
string(10) "2017-02-07"
}
["Contribuyentes Convenio Multilateral"]=>
array(13) {
[0]=>
string(10) "2017-01-13"
[1]=>
string(10) "2017-02-13"
}
}
}
导致内存不足错误的循环在哪里?您的错误在
month()函数的foreach
中:
$response = month($var);
您应该在$item
变量上运行month()
函数
下面是可怜的编译器正在尝试做的事情:
month()
循环遍历$var
使用传入的参数调用month()
month()
被调用。。。等等
第4步与第1步相同,因此编译器一直在尝试运行您的代码,而您的代码只是反复运行相同的函数:“(foreach($var as$item){$response=month($var);}”
您使用的是$var
而不是$item
。那么,编写代码以实现我的目标的正确方法是什么呢?我想得到以下信息:array(1){[258]=>array(9){[“recaudacion”]=>array(13){[0]=>string(10)“2017-10-07”}[“Contribuentes Conventio多边协议”]=>array(13){[0]=>string(10)“2017-10-13”}}
也就是说,过滤除当前month@MetaCode我认为您需要做的就是将月份($var);
更改为月份($item);