I looked around and can't quite find the answer for this, so I'm wondering if I contain an array such as this..
$array['foo']['bar'][1] = '';
$array['foo']['bar'][2] = '';
$array['foo']['bar'][3] = '';
$array['foo']['bar'][4] = '';
How can I check if all the values are empty? I tried doing the following:
if (empty($array['foo']['bar'])) {
// Array empty
}
But as expected that didn't work.
How can I do this?
$array['foo']['bar']
isn't empty because it's actuallyarray(1=>'',2=>'',3=>'',4=>'')
.You would need to do a
foreach
loop on it to check if it is indeed all empty.If you wanted to check to see if all of the values where populated you can use
For what you want to do though you could use array reduce with a closure
Note this will only work in php 5.3+
A short alternative would be:
Note that some single values may be considered as empty. See empty().