我嘗試將一個新數組插入到一個數組中我嘗試使用模塊化切割它并將其反轉<?phpliteral(12);function literal($sum){$n;for($i=0;$i<$sum;$i++){ $n[] = $i+1; echo $n[$i]; $length = strlen($n[$i]);//count length reset every loop $keeper = $n[$i]; //store on new variable reset every loop for($m=0;$m<$length;$m++){ if($keeper>=10){//just skip if below ten $newstore[$m] = $keeper%(10^($length-($m+1))); $keeper = floor($keeper/10); }else { $newstore[$m] = $keeper;// this value to keep array and reset it, then keep it again } } $newstored = array_reverse($newstore);//reverse it and reset again for($a=0;$a<count($newstored);$a++){ $fixed[] = $newstored[$a]; }}echo nl2br("\n".count($n)."\n");for($i=0;$i<count($fixed);$i++){ echo $fixed[$i];}echo nl2br("\n".count($fixed));}?>我想要的[1,2,3,4,5,6,7,8,9,1,0,1,1,1,2] 結果是我得到的實際結果[1,2,3,4,5,6,7,8,9,1,1,0,1,1,0,1,1]謝謝
3 回答

互換的青春
TA貢獻1797條經驗 獲得超6個贊
要獲得所需的結果,您可以使用1-12的范圍并使用implode將其轉換為字符串。
然后使用str_split創建結果數組。
$res = str_split(implode(range(1,12)));
print_r($res);
結果:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 1
[10] => 0
[11] => 1
[12] => 1
[13] => 1
[14] => 2
)
- 3 回答
- 0 關注
- 132 瀏覽
添加回答
舉報
0/150
提交
取消