计算所有整数数组的升序数组

时间:2015-08-28 05:35:33

标签: php arrays int

我有一个问题:"计算所有整数数组的升序数组"。

我的代码:

<?php
$arrInt = array(1, 2, 3, 4, 5, 1, 2);

function numArrChildAscending($index, $indexcount, $array = array()){
    $numcount = 0;

    if ($index >= count($array) || $index < 1 || $index + $indexcount >= count($array)){
        return $numcount;
    }

    $flag = true;

    for ($i = $index; $i <= ($index + $indexcount - 1); $i++){
        if ($array[$i] <= $array[$i - 1]){
            $flag = false;
            break;
        }
    }

    if ($flag == true){
        $numcount++;
    }

    //echo 'count 1 :' . $numcount . '<br />';

    for ($i = $index + 1; $i < count($array); $i++){
        $numcount = $numcount + numArrChildAscending($i, $indexcount, $array);
    }

    //echo 'count 2 :' . $numcount . '<br />';

    for ($i = $indexcount; $i < count($array); $i++) { 
        $numcount = $numcount + numArrChildAscending($index, $i, $array);
    }

    //echo 'count 3 :' . $numcount . '<br />';


    return $numcount;
}

echo numArrChildAscending(1, 2, $arrInt);

结果如下:

Fatal error: Maximum function nesting level of '256' reached, aborting!
in D:\VertrigoServ\www\learningphp.vn\index.php on line 7

2 个答案:

答案 0 :(得分:0)

将此行放在您的php文件中。

ini_set('xdebug.max_nesting_level', $limit)

确保您已安装xdebug

答案 1 :(得分:-1)

修改您的php.ini文件:在xdebug.max_nesting_level中搜索XDebug section。增加价值。