Today i ran into a PHP gotcha, and it had me stumped for a few minutes so i thought i'd share it with you.
$found = false;
foreach($arr as &$item) {
if ($item['type'] == "mytype") {
$found = true;
break;
}
}
if (!$found) {
$item = [ 'type' => 'mytype' ];
$arr[] = $item;
}
This was causing my custom item at the end to show up twice in my list and i was completely confused.
If you'd like to guess why.
I see why it happened but I find this to be unintuitive.