Announcement

Collapse
No announcement yet.

PHP code help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP code help

    I have something that works so just for my curiosity/annoyance...Why does the first work but not the others?

    Code:
    This works:
                   foreach ($arrFiles as $row) {
                           $firstRow = $row['name'];
                           break;
                   }
    This doesn't:
                   $row = each($arrFiles);
                   $firstRow = $row['name'];
    This doesn't:
                   $row = array_split($arrFiles, 0, 1);
                   $firstRow = $row['name'];
    The error is: Undefined index: name
    Which tells me the array pair key is not there anymore?

    The array is generated by:
    Code:
    while (($file = readdir($dir)) !== false) {
        if ( preg_match( "/$fileName\\.[0-9]{10,}/", "$file"  ) == 1 ) {
            $time = filemtime(HISTORY_PATH.$file);
            $arrayRows["$time"] = array( 'name'=>$file,
                                         'size'=>filesize(HISTORY_PATH.$file),
                                         'time'=>$time);
        }
    }

  • #2
    I think your problem is you didnt pay a nerdier nerd than you to make the script.
    NOSTALGIA IN THE WORST FASHION

    internet de la jerome

    because the internet | hazardous

    Comment


    • #3
      www.php.net is your friend
      Code:
      1:Pred_FNM <ER>> guys, yellow + green is really shitty for forumcolours :p
      1:lnx> what's wrong with that combination
      1:lnx> I wear yellow-green clothes :(
      1:Pred_FNM <ER>> i dont mean in clothes, in forums..
      1:lnx> kk
      1:lnx> buy a black-white computer monitor if you don't like the colors foo

      Comment


      • #4
        Take away "each"..
        hmm so do u have to assign in php


        1:delta> personally, i would not go to war for oil
        1:FarScape> in age of empires you would
        1:Freeze> LOL FAR
        ---
        5:waven> freeze
        5:waven> no one talks to ease directly
        5:waven> you state your business with sanji
        5:waven> he will relay it to phizey
        5:waven> phizey will relay it to me
        5:waven> and i will talk to ease
        5:Freeze> LOL
        5:waven> that's how things work around here
        --
        1:renzi> freeze theres difference between being wasted and being a waste

        Comment


        • #5
          php.net usually has all the answers but this one was a little convoluted, I guess.

          a wet n00dle to the rescue:

          > Because name is not a key in the array. The keys in the array resulting
          > from each are 0, 1, key, and value.
          >
          > The functionally corresponding code would be:
          >
          > list(, $row) = each($arrFiles);
          > $firstRow = $row['name'];

          Comment

          Working...
          X