+ 1

How to check multidimensional empty array in php? key exist and value empty

i have a large multidimensional array, it may have empty values if it has all empty values then i do not want to insert this data into database. how i can check before inserting into database?

9th Aug 2019, 3:29 PM
Muhammad Idrees 🇵🇰
Muhammad Idrees 🇵🇰 - avatar
2 odpowiedzi
+ 11
It would be great to see an example. Generally speaking, you can do it by using foreach and empty($yourArray[$key]).
16th Aug 2019, 5:56 AM
Igor Makarsky
Igor Makarsky - avatar
+ 3
$inputs = [ 'id' => 123, 'last' => '', 'password' => '', 'email' => null ]; $filtered = array_filter($inputs, function ($key) { return $key != '' || $key != null; }); if(count($filtered) > 1){ echo "we will inserte into dbase"; }else{ echo "we will not insert into dbase"; }
19th Aug 2019, 6:15 AM
Muhammad Idrees 🇵🇰
Muhammad Idrees 🇵🇰 - avatar