Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Location
    PA
    Posts
    303

    Assigning numbers

    I’m trying to assign numbers automatically ex:

    1 we
    2 hi
    3 hello

    Using the following code:

    PHP Code:
    while (false !== ($entry $d->read()))
    {

    if (
    $entry != "." && $entry != ".."
    {

    $test .= $number." . ".$entry."\"
    "
    ;
    }

    Any advice is appreciated

  2. #2
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,104
    Try this:

    PHP Code:
    $number 1;
    while(
    false !== ($entry $d->read()))
    {
       if (
    $entry != "." && $entry != "..")
       {
           
    $test .= $number." . ".$entry."\n";
           ++
    $number;
       }

    However, if all you want to do is get a list of files from a directory, this might be more efficient:

    PHP Code:
    // -- All files
    $list glob("path/to/some/directory/*.*");

    // -- All text files
    $list glob("path/to/some/directory/*.txt");

    // -- All images
    $list glob("path/to/some/directory/{*.gif,*.png,*.jpeg,*.jpg}"GLOB_BRACE);

    if (
    is_array($list))
    {
       foreach(
    $list as $filename)
       {
           if (
    is_file($filename))
           {
               
    $files[] = $filename;
           }
       }
    }

    // -- Now you have all files in $files, so to print your output

    foreach($files as $number => $filename)
    {
        
    $test .= $number." . ".$filename;

    Hope this helps

  3. #3
    Join Date
    Aug 2003
    Location
    PA
    Posts
    303
    thanks alot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •