PHP foreach if help

Hey there,

Firstly, i’m new here so please forgive me if this is in the wrong area etc.

I have a php problem i’ve been battling with for the past few hours.

Basically, i want to run a foreach (on an array), but only if 1 part of the array is less than another part.

<?php

// needs to run a check to see if $setlive is less than $updated from within the array
// if $setlive < $updated then output

$is_setlive = $data["setlive"];

if ($is_setlive) 
{
    foreach($is_setlive as $user)
    
    {
        $editurl        = SITE_URL . "/admin/modifyuser.php?userid=" . $user["id"];
        $title          = $user["username"];
        $centre_name    = $user["centre_name"];
        $registeredon   = $user["registered_on"];
        $updated	    = $user["updated"];
        $setlive	    = $user["setlive"];
        $id             = $user["id"];
    }
    
    
?>

Any help would be amazing.

Thanks
André

what’s the problem? The code you posted is missing a closing } which would show up as a syntax error.

The entire code is:

<?php

// needs to run a check
// if $setlive < $updated then output

// check /admin/dashboard.php

$is_setlive = $data["setlive"];

if ($is_setlive) 
{
    foreach($is_setlive as $user)
    
    {
        $editurl        = SITE_URL . "/admin/modifyuser.php?userid=" . $user["id"];
        $title          = $user["username"];
        $centre_name    = $user["centre_name"];
        $registeredon   = $user["registered_on"];
        $updated	    = $user["updated"];
        $setlive	    = $user["setlive"];
        $id             = $user["id"];
    }
    
    
?>

<div class="list" id="activities"> 
	<li class="activity"> 
		<div class='tools'><small><?php echo date('jS F Y h:i', $setlive); ?></small></div> 
		<tt><a href="<?php echo $editurl; ?>"><img class="gravatar" alt="" width="16x16" height="16x16" style="" src="<?php echo SITE_URL ?>/_resources/img/avatar.jpg" /></a> 
<a href="<?php echo $editurl; ?>"><?php echo $centre_name; ?></a> updated on <?php echo date('jS F Y h:i', $updated); ?> and set live on <?php echo date('jS F Y h:i', $setlive); ?>.</tt>
	</li>
</div>   
   
<?php } else { ?>
    
<div class="list" id="activities"> 
	<li class="activity"> 
	<tt>No dive centres pending.</tt>
	</li>
</div>
    
<?php } ?>

just to confirm, i’m only looking to list anything that has $setlive less than $updated.

<?php

// needs to run a check
// if $setlive < $updated then output

// check /admin/dashboard.php

$is_setlive = $data["setlive"];

if ($is_setlive) 
{
    foreach($is_setlive as $user)
    
    {

     if($user["setlive"] >= $user["updated"]) continue; 

        $editurl        = SITE_URL . "/admin/modifyuser.php?userid=" . $user["id"];
        $title          = $user["username"];
        $centre_name    = $user["centre_name"];
        $registeredon   = $user["registered_on"];
        $updated	    = $user["updated"];
        $setlive	    = $user["setlive"];
        $id             = $user["id"];
    }
    
    
?>

<div class="list" id="activities"> 
	<li class="activity"> 
		<div class='tools'><small><?php echo date('jS F Y h:i', $setlive); ?></small></div> 
		<tt><a href="<?php echo $editurl; ?>"><img class="gravatar" alt="" width="16x16" height="16x16" style="" src="<?php echo SITE_URL ?>/_resources/img/avatar.jpg" /></a> 
<a href="<?php echo $editurl; ?>"><?php echo $centre_name; ?></a> updated on <?php echo date('jS F Y h:i', $updated); ?> and set live on <?php echo date('jS F Y h:i', $setlive); ?>.</tt>
	</li>
</div>   
   
<?php } else { ?>
    
<div class="list" id="activities"> 
	<li class="activity"> 
	<tt>No dive centres pending.</tt>
	</li>
</div>
    
<?php } ?>

awesome, thank you! :slight_smile: