Array question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Array question

Post by Addos »

Hi,
Looking for some help on this as I need to pass $heading_dates = array('2009','2010'); to
if($date = substr($date, -4) == $heading_dates[0]) but I’m not sure how to get the $heading_dates[] to return $heading_dates[0] and $heading_dates[1] to if($date = substr($date, -4)

I think I might need a loop to return the index from the array but I’m not really sure. I know I could simply write out the code twice to pass the '2009','2010' dates to each but I’m really wanting to get the hang of using less code even if this is not a big chunk of script.
Thanks for any help


Code: Select all

// Look for future dates beyond present one   
           do {
        $heading_dates = array('2009','2010');
        
         $date = $row_GetEngag['heading'];
  if($date = substr($date, -4) == $heading_dates[????]) {
                
    echo "<br><h1>Future Engagements</h1> ";
 
     ?>
        <a href=" results.php?id=<?php echo $row_GetEngag['engage_id']; ?>">                     <?php echo $row_GetEngag['heading']; ?></a><br />
    <?PHP } ?>    
       <?php } while ($row_GetEngag = mysql_fetch_assoc($GetEngag)); ?>
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Re: Array question

Post by Hannes2k »

Hi,
why do you don't use the in_array() function?
Post Reply