Handling arrays with GLOB item

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ExeByte
    New Member
    • Nov 2015
    • 3

    Handling arrays with GLOB item

    I have the following code to get the list of images from a directory. Then I will display them I manage to get them, but when I try to display I only see the first one:
    Code:
    array($timg);
      	$JCOUNT=0; 
      	$JTOT = 0;
    	$tts = $dirname."/{*.jpg}";
      	foreach(glob($tts,GLOB_BRACE) as $tt){ 	
    	$JCOUNT=$JCOUNT+1; print_r2("JCOUNT = $JCOUNT");
    	$timg[$JCOUNT] = $tt; print_r2("timg = $timg[$JCOUNT]");
    	$JTOT++; print_r2("JTOT = $JTOT");};
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you haven’t posted the code that should display the images.

    additionally, use print_r($timg) to show the contents.

    PS. reindexing the array looks pretty pointless to me as you could easily do that on the fly:
    Code:
    foreach (glob($tts, GLOB_BRACE) as $index => $tt) {
        printf('%d) %s' . PHP_EOL, ++$index, $tt);
    }

    Comment

    • ExeByte
      New Member
      • Nov 2015
      • 3

      #3
      Thank you You are right I do not need to reindex it. In fact I should have formulated the question in a different way. For that I will open up another thread.Thanks again.

      Comment

      Working...