PHP - Checking for empty element in 2D array -


i have array looks following

array:2 [▼   0 => array:1 [▼     "input1" => "something"   ]   1 => array:1 [▼     "input2" => ""   ] ] 

now first element have data. second element interested in. @ moment, trying this

if(!empty($clientgroup[0][1]) || !empty($clientgroup[1][1]))     var_dump("some data"); } else {     var_dump("both empty"); } 

the else should triggered if both elements empty e.g.

array:2 [▼   0 => array:1 [▼     "input1" => ""   ]   1 => array:1 [▼     "input2" => ""   ] ] 

if 1 of them have data, if should triggered (so first array showed, if should triggered).

how go doing this, empty not seem work.

thanks

the 2nd level keys not exist told values empty. change line

if(!empty($clientgroup[0][1]) || !empty($clientgroup[1][1])) 

to,

if(!empty($clientgroup[0]['input1']) || !empty($clientgroup[1]['input2'])) 

and should results you're after.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -