Question: I have a php foreach loop my code is:

```
<?php 
  foreach($items as $item){

    echo $item->date;
    echo $item->title;
   }
?>

```

my out put for example this is:

> 
> 2014-08-23
> 
> 
> title1
> 
> 
> 2014-08-23
> 
> 
> title2
> 
> 
> 2014-08-30
> 
> 
> title3
> 
> 
> 

but i want echo my item this format:

> 
> 2014-08-23
> 
> 
> title1
> 
> 
> title2
> 
> 
> 2014-08-30
> 
> 
> title3
> 
> 
> 

i want echo Equal dates once and show items. how can do it? thank you

Answer: 
You can try this

```
$temp = array();
foreach($items as $item){
    if (!in_array($item->date, $temp)){
        $temp[$item->title] = $item->date;
    }
}

foreach($temp as $title=>$date){       
    echo $date.'</br>';
    echo $title.'</br>';
}

```
```
$last_date = null;
foreach($items as $item){
    if ($item->date != $last_date) {
        echo $item->date;
        $last_date = $item->date;
    }
    echo $item->title;
}

```