Reputation: 1
I would like to add /images/ to my array output and remove . and .. from the start of the array as well eg.
from
Array ( [0] => . [1] => .. [2] => 15216151220552.jpg [3] => 15542647385762.png [4] => 15544894045853.jpg [5] => 15704627111960.jpg [6] => 15738494275643.jpg [7] => 15908484237853.jpg [8] => 15908493560753.jpg [9] => 163d7e3.jpg [10] => 1_44_c.png [11] => 1a152e0.jpg [12] => 20200909_110828.jpg [13] => 20be31a.jpg [14] => 28639f0.jpg [15] => 468db69.jpg [16] => 51d4aba.jpg [17] => 5a73df5.jpg [18] => 5cb3a91.jpg [19] => 666a4b9.jpg [20] => 7120d2a.jpg )
to
Array ( [0] => /images/15216151220552.jpg [1] => /images/15542647385762.png [2] => /images/15544894045853.jpg [3] => /images/15704627111960.jpg [4] => /images/15738494275643.jpg [5] => /images/15908484237853.jpg [6] => /images/15908493560753.jpg [7] => /images/163d7e3.jpg [8] => /images/1_44_c.png [9] => /images/1a152e0.jpg [10] => /images/20200909_110828.jpg [11] => /images/20be31a.jpg [12] => /images/28639f0.jpg [13] => /images/468db69.jpg [14] => /images/51d4aba.jpg [15] => /images/5a73df5.jpg [17] => /images/5cb3a91.jpg [17] => /images/666a4b9.jpg [18] => /images/7120d2a.jpg )
the array is an output from
<?php
$dir0 = 'C:\Users\example\Pictures\desktop\backgrounds';
$scan0 = scandir($dir0);
?>
Upvotes: 0
Views: 68
Reputation: 1147
Those are the current (.) and parent (..) directories. They are present in all directories, and are used to refer to the directory itself and its direct parent.
$array = array_diff(scandir($dir), ['..', '.']);
to add 'images':
$arrayWithPrefix = substr_replace($array, 'images/', 0, 0);
Upvotes: 1