NYCPHP Meetup

NYPHP.org

[nycphp-talk] foreach ERROR

Flavio daCosta nyphp at n0p.net
Wed Jul 19 09:32:44 EDT 2006


I haven't been following along, so forgive me if this has been already
covered.  Looking at the error and the code, for one, I can see a
problem with the path.  You are in '.../Audio/mp3', what you want is
'../Music'.  Secondly, I'm not really sure what your objectives are, but
it appears that some simplification is in order.

Food for thought:

<?php
$dir    = '../Music';
$return = array ();
foreach (glob ("$dir/*.mp3") as $item)
{
    $return[] = basename ($item);
}
print_r($return) ;
?>


> From: "CED" <Consult at CovenantEDesign.com>
> This is the most recent, and stripped down, state:
> 
> <?
> $dir = '../Audio/Music';
> foreach(glob("$dir/*.mp3") as $item){$sort[] = (end(explode('/',$item)));}
>     foreach($sort as $item){$return[]= $item;}
>      if(!$return){return array();}
> 
>   echo($return[0]) ;
>   ?>
> 
> And this is still the error:
> 
> Warning: Invalid argument supplied for foreach() in
> /hsphere/local/home/skoilnog/edwardprevost.info/Audio/mp3/Audio.php on line
> 4



More information about the talk mailing list