函数调用时出现意外的T_VARTIABLE

时间:2014-01-27 01:48:19

标签: php

我正在尝试生成一组随机卡但我不想重复,所以我使用randWithout来散发已生成的数字。但是我得到一个 Parse错误:语法错误,意外的T_VARIABLE,期待'('在$ which_card行,我做错了什么?

 $exceptions = array();

 $which_card = $this->randWithout(0,count($Card_array['Suits']-1), array $exceptions);

排除功能

function randWithout($from, $to, array $exceptions) {
    sort($exceptions); // lets us use break; in the foreach reliably
    $number = mt_rand($from, $to - count($exceptions)); // or mt_rand()
    foreach ($exceptions as $exception) {
        if ($number >= $exception) {
            $number++; // make up for the gap
        } else /*if ($number < $exception)*/ {
            break;
        }
    }
    return $number;
}

2 个答案:

答案 0 :(得分:3)

$this->randWithout(0,count($Card_array['Suits']-1), array $exceptions);
                                                    ^---- this is causing it

您无需在函数调用

中指定变量保存数组

答案 1 :(得分:1)

$which_card = $this->randWithout(0,count($Card_array['Suits'])-1, $exceptions)

如何从函数中删除“数组”并将-1移至计数外?我同意这似乎有点可疑