PHP Max Function Help

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
PHP:
<?php
if (!defined('ROOT'))
    die;

function createGalleryDirectories() {
   $path = ROOT.'gallery/events';
   $dir_handle = @opendir($path) or die("Unable to open $path");
   $count = "0";
   while ($file = readdir($dir_handle)) {
      if ($file!="." && $file!="..") {
         $galleryDirectory[$count] = $file;
         $count++;
      }
   }
   closedir($dir_handle);
   
   $i = "0";
   while ($i < $count) {
      list($oldCaption, $year, $order) = explode("-", $galleryDirectory[$i]);
      $caption["$year"][$order] = str_replace("_", " ", "$oldCaption");
      /*
      list($oldCaption[$i], $year[$i], $order[$i]) = explode("-", $galleryDirectory[$i]);
      $caption[$i] = str_replace("_", " ", "$oldCaption[$i]");
      */
      $i++;
   }
   
   /*
   $ii = "0";
   $numYears = count($caption);
   while ($ii < $numYears) {
      $year = max($caption);
      $html .= "<fieldset class=\"gallery\">";
      $html .= "<legend class=\"gallery\">$year</legend>";
   }
   */
   
   /*
   $ii = "0";
   $iii = "0";
   $yearDB = array();
   while ($ii < $count) {
      if (!in_array($year[$ii], $yearDB)) {
         $yearDB[$iii] = $year[$ii];
         $ii++;
         $iii++;
      } else {
         $ii++;
      }
   }
   */
   
   
   echo $count;
   echo "<br />";
   echo $i;
   echo "<br />";
   echo count($caption);
   echo "<br />";
   echo $caption;
   echo "<br />";
   echo $year;
   echo "<br />";
   echo $caption['2009'];
   echo "<br />";
   echo max($caption);
//echo $html;
}
?> 
<!--
<fieldset class="gallery">
<legend class="gallery">2009</legend>
<div class="row">          
   <div class="cell"><a href=""><img src="events/Marlboro_Day-2009/picture0.jpg" /></a><div class="caption">Marlboro Day</div></div>
   <div class="cell"><a href="images/image-1.jpg" rel="lightbox[roadtrip]">image #1</a></div>
</div>
</fieldset>
-->
gives me:
Code:
3
3
2
Array
2009
Array
Array

how do I get the max function to display "2009" rather than Array?
btw the file directory is in the attachments.
 

Attachments

  • help.jpg
    help.jpg
    47.3 KB · Views: 34

zapzack

New Member
Messages
606
Reaction score
19
Points
0
can you do
Code:
echo print_r(max($caption));
 
Last edited:

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
actually I already fixed it.
PHP:
$maxYear = max(array_keys($caption));

credit
 
Top