我正在尝试添加循环,但出现错误...我试图在每个循环之前清除数组,但对我不起作用。
<?php
for ($aw = 1; $aw <= 49; $aw++) {
$cart = array("orange", "banana");
$result = array();
$combination = array();
function combinations(array $myArray, $choose) {
global $result, $combination;
$n = count($myArray);
function inner ($start, $choose_, $arr, $n) {
global $result, $combination;
if ($choose_ == 0) array_push($result,$combination);
else for ($i = $start; $i <= $n - $choose_; ++$i) {
array_push($combination, $arr[$i]);
inner($i + 1, $choose_ - 1, $arr, $n);
array_pop($combination);
}
}
inner(0, $choose, $myArray, $n);
return $result;
}
$array=combinations($cart, 6); // this is your 2d array
$counnumber=1;
foreach ($array as $row) {
$counnumber++;
}
echo $counnumber;
}
我收到以下错误
Fatal error: Cannot redeclare combinations() (previously declared in
/home/www/mywebsite.com/checkingerror.php:11) in
/home/www/mywebsite.com/checkingerror.php on line 11
请检查以下代码,并帮助我!
谢谢