Reputation: 2112
I want to assign values of pathinfo function to variables like so:
list($dirname, $basename, $extension, $filename) = pathinfo($path_image);
echo $dirname.$basename.$extension.$filename;
However there is no output.
But if I run only:
print_r(pathinfo($path_image));
I get output like so:
Array ( [dirname] => http://blah.com/images [basename] => image123.jpg [extension] => jpg [filename] => image123)
Upvotes: 1
Views: 1391
Reputation: 12168
list()
is not a function, it is a language construction.From php.net:
this is not really a function, but a language construct
list() only works on numerical arrays and assumes the numerical indices start at 0.
To fix that, you may try to ommit result array keys by array_values()
, as mentiononed in answer of @anupam:
<?php
$values = array_values(pathinfo($path_image));
list($dirname, $basename, $extension, $filename) = $values;
?>
Upvotes: 5
Reputation: 2112
Work:
list($dirname, $basename, $extension, $filename) = array_values(pathinfo($wallpaper_image));
echo $dirname.$basename.$extension.$filename;
Upvotes: 2
Reputation: 756
pathinfo() returns an associative array. So, your code should work as follows:
list($dirname, $basename, $extension, $filename) = array_values(pathinfo($path_image));
Upvotes: 2