How to divide similar data when printing an array?

When printing the array I need to split the data in the form. In this particular case, the key type, which can have a value from one to nine. That is, when the type is changed from one to two, I want to display the tag hr. And the question is how to explain to the foreach loop that the values have changed.

An example of the array:

[113] => Array
(
 [id] => 113
 [date] => 2019-12-17
 [ok] => 
 [comment] => 
 [text] => Some text
 [type] => 1
)
[114] => Array
(
 [id] => 113
 [date] => 2019-12-17
 [ok] => 
 [comment] => 
 [text] => Some text
 [type] => 2
 )
April 3rd 20 at 18:28
1 answer
April 3rd 20 at 18:30
Solution
$prevType = null;
foreach($items as $item) {
 if ($item[type] !== $prevType) { // type changed
 // do something
}
 $prevType = $item[type];
}

Find more questions by tags PHP