mercredi 30 mai 2018

PHP check if "multidimensional array(array([key]=>value))" values is empty

I have this array I am posting in Laravel from my view to my controller, and I am trying to check if there is any values inside the array, the array is initialized and sent to the view and inside the view I have a table with inputs to fill, if the user doesn't fill the table and submits the form, the array will come back as following:

Array
(
[51] => Array
    (
        [5] => 
        [2] => 
        [8] => 
    )

[78] => Array
    (
        [18] => 
        [23] => 
        [21] => 
    )
)

for clarification and communication:

array(
   [key1]array(
     [key1_1]=>value
   )
)

and I want to check if all of value are empty or not which they are in this example, it would be something similar to empty($array) for 1 dimensional arrays.

I have tried array_filter() but it doesn't serve if the value is inside a key inside a key inside an array.

I know I can use foreach to enter to key1 and then foreach again to enter key1_1 and recursively check if the value is null or not and return false and break the loop whenever a value is not null.

But is there any other way or a method in PHP that allows checking those values? something similar to empty($array) but goes inside the array and checks value only? or something that has the logic of array_filter(array_filter(empty($array)))?

or there is no other way except recursively check each value manually by using foreach?

NOTE: I am using Laravel 5.5, PHP 7.1.9

NOTE: I am not trying if find a specific value is null, I am asking if there is a built-in method in PHP or a simpler method than the one I use to check if the values are all null or not.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2LIYFdW
via IFTTT

Aucun commentaire:

Enregistrer un commentaire