CodeIgniter Forums
For loop with var dump question. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: For loop with var dump question. (/showthread.php?tid=64498)



For loop with var dump question. - wolfgang1983 - 02-26-2016

When I var dump my $orignal_images. Because it is in the for loop it displays the var dump array multiple times as shown below.

PHP Code:
array (size=6)
 
 0 => string 'assian_creed_3.jpg' (length=18)
 
 1 => string 'assian_creed_4.jpg' (length=18)
 
 2 => string 'ci-logo.png' (length=11)
 
 3 => string 'kitten_1.jpg' (length=12)
 
 4 => string 'nvidia_5-wallpaper-1920x1080.jpg' (length=32)
 
 'sub\' => 
    array (size=1)
      0 => string '
Windows_7_wallpaper_8_thumb-100x100.jpg' (length=39)

array (size=6)
  0 => string '
assian_creed_3.jpg' (length=18)
  1 => string '
assian_creed_4.jpg' (length=18)
  2 => string '
ci-logo.png' (length=11)
  3 => string '
kitten_1.jpg' (length=12)
  4 => string '
nvidia_5-wallpaper-1920x1080.jpg' (length=32)
  '
sub\' => 
    array (size=1)
      0 => string '
Windows_7_wallpaper_8_thumb-100x100.jpg' (length=39)

array (size=6)
  0 => string '
assian_creed_3.jpg' (length=18)
  1 => string '
assian_creed_4.jpg' (length=18)
  2 => string '
ci-logo.png' (length=11)
  3 => string '
kitten_1.jpg' (length=12)
  4 => string '
nvidia_5-wallpaper-1920x1080.jpg' (length=32)
  '
sub\' => 
    array (size=1)
      0 => string '
Windows_7_wallpaper_8_thumb-100x100.jpg' (length=39)

array (size=6)
  0 => string '
assian_creed_3.jpg' (length=18)
  1 => string '
assian_creed_4.jpg' (length=18)
  2 => string '
ci-logo.png' (length=11)
  3 => string '
kitten_1.jpg' (length=12)
  4 => string '
nvidia_5-wallpaper-1920x1080.jpg' (length=32)
  '
sub\' => 
    array (size=1)
      0 => string '
Windows_7_wallpaper_8_thumb-100x100.jpg' (length=39)

array (size=6)
  0 => string '
assian_creed_3.jpg' (length=18)
  1 => string '
assian_creed_4.jpg' (length=18)
  2 => string '
ci-logo.png' (length=11)
  3 => string '
kitten_1.jpg' (length=12)
  4 => string '
nvidia_5-wallpaper-1920x1080.jpg' (length=32)
  '
sub\' => 
    array (size=1)
      0 => string '
Windows_7_wallpaper_8_thumb-100x100.jpg' (length=39) 


Question how to only make it display one array result in the var dump.

PHP Code:
$get_directory $this->input->get('directory');

if (isset(
$get_directory)) {
    
    $cached_images
[] = directory_map('./images/cache/' $get_directory);

} else {
    
    $cached_images
[] = directory_map('./images/cache/catalog/');
    
}
        
for ($i=0$i count($cached_images); $i++) {     

    $original_images 
str_replace('_thumb-' $width 'x' $height''$cached_images[$i]);

    var_dump($original_images);

    if (isset($get_directory)) {


        if (!is_file(FCPATH 'images/' $get_directory '/' $original_images[$i])) {
                    
            if 
(@unlink(FCPATH 'images/cache/' $get_directory '/' $cached_images[$i])) {

            } else {

            }

        }

    } else {

        if (!is_file(FCPATH 'images/catalog/' $original_images[$i])) {
                    
            if 
(@unlink(FCPATH 'images/cache/catalog/' $cached_images[$i])) {

            } else {
                            
            
}

        }
    }
            




RE: For loop with var dump question. - InsiteFX - 02-26-2016

(02-26-2016, 01:00 AM)wolfgang1983 Wrote: When I var dump my $orignal_images. Because it is in the for loop it displays the var dump array multiple times as shown below.

PHP Code:
array (size=6)
 
 0 => string 'assian_creed_3.jpg' (length=18)
 
 1 => string 'assian_creed_4.jpg' (length=18)
 
 2 => string 'ci-logo.png' (length=11)
 
 3 => string 'kitten_1.jpg' (length=12)
 
 4 => string 'nvidia_5-wallpaper-1920x1080.jpg' (length=32)
 
 'sub\' => 
    array (size=1)
      0 => string '
Windows_7_wallpaper_8_thumb-100x100.jpg' (length=39)

array (size=6)
  0 => string '
assian_creed_3.jpg' (length=18)
  1 => string '
assian_creed_4.jpg' (length=18)
  2 => string '
ci-logo.png' (length=11)
  3 => string '
kitten_1.jpg' (length=12)
  4 => string '
nvidia_5-wallpaper-1920x1080.jpg' (length=32)
  '
sub\' => 
    array (size=1)
      0 => string '
Windows_7_wallpaper_8_thumb-100x100.jpg' (length=39)

array (size=6)
  0 => string '
assian_creed_3.jpg' (length=18)
  1 => string '
assian_creed_4.jpg' (length=18)
  2 => string '
ci-logo.png' (length=11)
  3 => string '
kitten_1.jpg' (length=12)
  4 => string '
nvidia_5-wallpaper-1920x1080.jpg' (length=32)
  '
sub\' => 
    array (size=1)
      0 => string '
Windows_7_wallpaper_8_thumb-100x100.jpg' (length=39)

array (size=6)
  0 => string '
assian_creed_3.jpg' (length=18)
  1 => string '
assian_creed_4.jpg' (length=18)
  2 => string '
ci-logo.png' (length=11)
  3 => string '
kitten_1.jpg' (length=12)
  4 => string '
nvidia_5-wallpaper-1920x1080.jpg' (length=32)
  '
sub\' => 
    array (size=1)
      0 => string '
Windows_7_wallpaper_8_thumb-100x100.jpg' (length=39)

array (size=6)
  0 => string '
assian_creed_3.jpg' (length=18)
  1 => string '
assian_creed_4.jpg' (length=18)
  2 => string '
ci-logo.png' (length=11)
  3 => string '
kitten_1.jpg' (length=12)
  4 => string '
nvidia_5-wallpaper-1920x1080.jpg' (length=32)
  '
sub\' => 
    array (size=1)
      0 => string '
Windows_7_wallpaper_8_thumb-100x100.jpg' (length=39) 


Question how to only make it display one array result in the var dump.

PHP Code:
$get_directory $this->input->get('directory');

if (isset(
$get_directory)) {
    
    $cached_images
[] = directory_map('./images/cache/' $get_directory);

} else {
    
    $cached_images
[] = directory_map('./images/cache/catalog/');
    
}
        
for ($i=0$i count($cached_images); $i++) {     

    $original_images 
str_replace('_thumb-' $width 'x' $height''$cached_images[$i]);

    var_dump($original_images);

    if (isset($get_directory)) {


        if (!is_file(FCPATH 'images/' $get_directory '/' $original_images[$i])) {
                    
            if 
(@unlink(FCPATH 'images/cache/' $get_directory '/' $cached_images[$i])) {

            } else {

            }

        }

    } else {

        if (!is_file(FCPATH 'images/catalog/' $original_images[$i])) {
                    
            if 
(@unlink(FCPATH 'images/cache/catalog/' $cached_images[$i])) {

            } else {
                            
            
}

        }
    }
            



You can try this:

PHP Code:
   $original_images str_replace('_thumb-' $width 'x' $height''$cached_images[$i]);

 
   $temp_images str_replace('_thumb-' $width 'x' $height''$cached_images[$i]);

 
   var_dump($temp_images);

 
   $temp_images ''