satbir Posted November 27, 2017 Share Posted November 27, 2017 I need for loop to display images....but image name must start with 00... like 001.jpg, 002.jpg.I write my code like this..for ($i = 001; $i <= 10; $i++) { echo "<img src='Ony/Ony-Small/'.str_pad($i, 3, '0', STR_PAD_LEFT);.'.jpg' class='img-responsive mx-auto d-block center-block img-thumbnail'>"; }..but this is not working..can anybody suggest me the right way Link to comment Share on other sites More sharing options...
Barand Posted November 27, 2017 Share Posted November 27, 2017 sprintf() EG for ($i=1; $i<=10; $i++) { echo sprintf("%03d.jpg", $i) . '<br>'; } Link to comment Share on other sites More sharing options...
satbir Posted November 27, 2017 Author Share Posted November 27, 2017 Thanks Working Well Link to comment Share on other sites More sharing options...
benanamen Posted November 27, 2017 Share Posted November 27, 2017 Alternate solution <?php foreach (range(0,10) as $d) { echo "<img src='Ony/Ony-Small/".sprintf('%02d', $d).".jpg' class='img-responsive mx-auto d-block center-block img-thumbnail'>\n"; } ?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.