theorise
theorise

Reputation: 7425

PHP, putting a looping variable from a foreach loop into a new array

I have this loop:

$dir = 'url/dir/dir/'; 
$images_array = glob($dir.'*.jpg'); 
foreach ($images_array as $image) {
     $image = str_replace($dir, '', $image);   
}  

I just want to save the $image variables into a new array. How is this possible?

Upvotes: 0

Views: 172

Answers (1)

hsz
hsz

Reputation: 152216

$dir = 'url/dir/dir/'; 
$images_array = glob($dir.'*.jpg'); 

$images = array();

foreach ($images_array as $image) {
     $images[] = str_replace($dir, '', $image);   
}

var_dump($images);

Upvotes: 4

Related Questions