mehidy Posted September 29, 2017 Share Posted September 29, 2017 I have got the auto increment process. Now I want to convert the auto increment value in to an array. I did below but result is not okay. I'm getting the below outputArray ( [0] => 110 ) But it should be as below.Array ( [0] => 100 [1] => 101 [2] => 102 [3] => 103 [4] => 104 [5] => 105 [6] => 106 [7] => 107 [8] => 108 [9] => 109 [10] => 110 ) Expecting you guideline/comments to get the desired output. How to do the coding. for($i = 100; $i <= 110; $i++) { echo $formattedNumber = sprintf('%03d', $i); //$formattedNumber1="$formattedNumber,"; } echo "</br>"; $myarray=array (); $myarray[] = $formattedNumber; print_r($myarray); Attached image is the result , when i run the code. Link to comment Share on other sites More sharing options...
requinix Posted September 30, 2017 Share Posted September 30, 2017 $formattedNumber depends on $i and $i only works inside the loop. If you want to add to an array then you have to add to it inside the loop. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.