【发布时间】:2015-08-28 05:35:32
【问题描述】:
我有一个问题:“计算所有整数数组的升序数组”。
我的代码:
<?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
【问题讨论】: