抱歉,如果标题有点混乱。
我被困在生成像这样的数组。如何生成像二进制数字反转阵列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
真棒!谢谢你,你救了我的一天 –