Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP array_walk does nothing?

Tags:

arrays

php

glob

I'd like to put each file name in $xsl_dir_path (absolute path) in select element. I've tried this:

$files = glob($xsl_dir_path . "/*.xsl");
array_walk($files, 'basename');

but it's not working at all, i can still see the full names of the files. I know i can apply basename when lopping through $files and build the option elements, but i'd like to do it before any html output.

like image 216
gremo Avatar asked Feb 28 '26 12:02

gremo


1 Answers

array_walk is useful when your callback function accepts a reference or when you use user-defined callback functions. In this case, the basename argument is not a reference.

What you want is array_map:

$files = glob($xsl_dir_path . "/*.xsl");
$files = array_map('basename', $files);
like image 99
netcoder Avatar answered Mar 03 '26 03:03

netcoder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!