I need to repeat a small piece of code several times so wrote a function which does not work, but when written outside of a function the code does work. I'm doing something daft but just can't see what it is!! Can someone please tell me how daft I am. Thank you.
This does not work:
function listfiles()
{$count=count($file);
for($z=0; $z<$count; $z++)
{$parts=explode("/",$file[$z]);
$parts=explode(".",$parts[1]);
print"<a href='$file[$z]'>$parts[0]</a><br><br>";}}
$file=glob("/xxx/xxx/files/*.*");
listfiles();
Yet this does:
$file=glob("/xxx/xxx/files/*.*");
{$count=count($file);
for($z=0; $z<$count; $z++)
{$parts=explode("/",$file[$z]);
$parts=explode(".",$parts[1]);
print"<a href='$file[$z]'>$parts[0]</a><br><br>";}}