How to check if a PHP POST array has any value set? -


i need check if item in array, part of $_post array, has value. values in empty array set, above example not produce desired results. (this array subset of full $_post array).

(  [columns] =>  [coached_textbox] => 1 [item] => array     (         [first] => array             (                 [coach_menu_value] => 1                 [coach_menu_name] => menu 1             )         [second] => array             (                 [coach_menu_value] =>                  [coach_menu_name] =>              )      ( 

is there simple way test if either array item has value? test each item in array value, seems inelegant.

this example provided in earlier post gives fine example on how test code initialized array() values.

if ($signup_errors) {   // there error } else {  // there wasn't } 

however, doesn't work on array set within $_post array.

use recursive function below traverse array. function return true if array contains at least 1 non-null value or non-empty string.

function traversearray($arr){     $flag = false;     foreach($arr $value){         if(is_array($value)){             $flag = traversearray($value);             if($flag) return true;         }else{             if(isset($value) && $value != '') return true;         }     }     return $flag; } 

and how should call function,
(suppose $array original array)

$isnonemptyarray = traversearray($array); if($isnonemptyarray){     // @ least 1 element in array either      // non-null value or non-empty string }else{     // array empty } 

here's live demo: https://eval.in/847211


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -