I’m working on the following code:
// $data has only one dimension AND at least one of its values start with a "@"
if ( (count($data) == count($data, COUNT_RECURSIVE))
&& (count(preg_grep('~^@~', $data)) > 0) )
{
// do nothing
}
else
{
// do something
}
The logic of this condition is working just fine, however, I would prefer if I could get rid of the empty if block while evaluating the second condition only if the first one yields true – otherwise the preg_grep() call will throw the following notice when $data has more than one dimension:
Notice: Array to string conversion
I know I could use the error suppression operator or some other hacky approaches, but I have the feeling that I’m missing something trivial. Can someone help me out, please?
First, obvious way:
Second, correct way