我有此數組:PHP:array_rand陣列
$nonTerminals = array("S","A","B");
$grammar = array(
"$nonTerminals[0]" => "aA",
"$nonTerminals[1]" => array("aA","bB"),
"$nonTerminals[2]" => array("bB","b")
);
,我用這個隨機值:
$rand_keys = array_rand($grammar, 2);
echo $grammar[$rand_keys[0]] . "\n";
但這是錯誤的,因爲它給我一些錯誤。
你能後你得到的錯誤?因爲現在,從我所看到的,你正試圖回顯一個數組.. –
而這些錯誤是? –
如果第二個或第三個被選中,你試圖回顯一個數組,可能是'Notice:Array to string conversion'。 – AbraCadaver