我尝试将一个新数组插入到一个数组中我尝试使用模块化切割它并将其反转<?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 关注
- 109 浏览
添加回答
举报
0/150
提交
取消