I am having some trouble understanding how to use Yoda conditions, I roughly get the way it works (Man is it hard finding a youtube video online). Can someone show me how to use Yoda conditions on this use case:
if ($parentId === null) {
foreach ($allCustomers as $customer) {
if ($customer['parentCustomer_id'] === '1') {
array_push($parentCustomers, $customer);
}
}
if (isset($parentCustomers[0])) {
$parentId = $parentCustomers[0]['customer_id'];
}
}
I understand the idea is it checks whether variables are properly compared to expressions. I just don't understand how to apply it properly.
It would be really helpful if someone could explain their answer so I can learn to apply it myself.