抱歉,如果標題有點混亂。
我被困在生成像這樣的數組。如何生成像二進制數字反轉陣列php
array(" one_third", " two_third", " two_third", " one_third", " one_third", " two_third", " two_third",..., " one_third", " one_third");
所以基本上我要像0, 1, 1, 0, 0, 1, 1, 0, 0
數組如何生成在PHP或任何其他progaming語言。
我試圖
$ass = array();
for($x = 0; $x <= 200; $x++){
if($x == 0){
array_push($ass, " one_third");
}else if($x == 1){
array_push($ass, " two_third");
}else{
if(count($ass) == 2){
array_push($ass, " two_third");
}else{
if($ass[count($ass)-1] == " two_third" && $ass[count($ass)-2] == " two_third"){
array_push($ass, " one_third");
}else if($ass[count($ass)-1] == " one_third" && $ass[count($ass)-2] == " one_third"){
array_push($ass, " two_third");
}
}
}
}
almost..but它是輸出'陣列 ( [0] => one_third [1] => two_third [2] = > two_third [3] => one_third [4] => two_third [5] => two_third [6] => one_third ... [N] => two_third )' 只有一個「one_third」後雙「two_third」 –
吶喊。對於那個很抱歉。編輯。 – cbrumsin
真棒!謝謝你,你救了我的一天 –