I need to return an array of filenames from the following function. I can't seem to get it to work, I keep getting NULL or blank when I var_dump($f);
test(9); //filename to test for are in array $line[9]
var_dump($f);
function test($b)
{
$in = fopen("datafeed.csv" , 'r');
$out = fopen("../scripts/output.txt", 'w');
while(($line = fgetcsv($in, 0, ',')) !== false)
{
$search = $line[$b];
$basename = pathinfo($search);
$i = strlen($basename['basename']);
$a = '0';
chdir("../images/");
while($i > $a)
{
$filename = substr($basename['filename'].'.'.$basename['extension'], $a, $i);
if(file_exists($filename))
{
$f = array($filename);
fputcsv($out, $f, ',');
return($f);
break; // Break out of this while
}
++$a;
}
}
}
fclose($in);
fclose($out);