I was doing this:
$attributes = array("a", "b", "c", "d","e","f", "g","h" ,"i","j","k","l");
foreach($all as $p) {
foreach($attributes as $key => $a) {
if (!$p->getAttribute($a)) {
unset($attributes[$key]);
}
}
}
But the unset seems to shrink the $attributes array in the loop and then unsets wanted values.
EDIT: This is not what happens. The real issue is that as these are nested loops, if !$p->getAttribute($a) returns false, I should not already unset it in the array, as the first loop foreach($all as $p) may provide $p with an attribute where it returns true, and thus needs to be kept.
I need it so that if !$p->getAttribute($a) then I want to remove the respective $a from $attributes. What’s the most efficient way to do it?
This is what I finally did:
EDIT: Solution has been edited due to my EDIT in the question itself…(aaawww, sorry for confusion).
Maybe not the most elegant and certainly not the most efficient (copying all needed elements…). But I have clear control about what’s going on and it works 🙂