I'm using this php code to get all the images from a folder and put all the results in an array:
<?php
$images = [];
$dir = 'images/*';
$file = glob($dir);
for ($x = 0; $x < count($file); $x++) {
$images[] = [ $file[$x] => $x];
}
print_r($images);
?>
Where i'm getting my results stored in the "$images" array:
print_r($images);
Output : /*Array ( [0] => Array ( [images/1.jpg] => 0 ) [1] => Array ( [images/2.jpg] => 1 ) [2] => Array ( [images/3.jpg] => 2 ) )*/
Now, i want to get the first value of the array in a string format, "images/1.jpg" i tried to print it out using its index but it displays the key and the word array in the beginning:
print_r($images[0]);
Output : /*Array ( [images/1.jpg] => 0 )*/
How to get only this value : "images/1.jpg" ?
Thanks.
echo($images[0]);... The command print_r add additional info. The command echo will just output the value.echoan array.