colap Posted March 22, 2012 Share Posted March 22, 2012 Array ( [Comment] => Array ( [post_id] => 1 [name] => cc [email] => [body] => spam ) ) How can i check if email is empty or not? Is there any php built in function? Should i use foreach? Link to comment https://forums.phpfreaks.com/topic/259474-how-can-i-check-if-associate-array-element-is-empty-or-not/ Share on other sites More sharing options...
mr.noname Posted March 22, 2012 Share Posted March 22, 2012 use this if( empty($str['comment']['email']) ) { // do something if empty value } else { // if not empty } Link to comment https://forums.phpfreaks.com/topic/259474-how-can-i-check-if-associate-array-element-is-empty-or-not/#findComment-1330104 Share on other sites More sharing options...
colap Posted March 22, 2012 Author Share Posted March 22, 2012 use this if( empty($str['comment']['email']) ) { // do something if empty value } else { // if not empty } What about isset and is_null function? Link to comment https://forums.phpfreaks.com/topic/259474-how-can-i-check-if-associate-array-element-is-empty-or-not/#findComment-1330105 Share on other sites More sharing options...
mr.noname Posted March 22, 2012 Share Posted March 22, 2012 let's check this for example if the variable assign to this value 0 ----> number 0 "0" ----> string 0 "" ----> empty string " " ----> string with whitespace 0.0 ----> double value array() ----> empty array NULL ----> null value FALSE -----> boolean false if use empty() ----> will return TRUE is_null() ---> return TRUE on NULL value isset() ---> all above are TRUE except FALSE and NULL value Link to comment https://forums.phpfreaks.com/topic/259474-how-can-i-check-if-associate-array-element-is-empty-or-not/#findComment-1330107 Share on other sites More sharing options...
mr.noname Posted March 22, 2012 Share Posted March 22, 2012 sorry for this is the example [/td] [td]empty() isset() is_null() 0 TRUE TRUE FALSE 0.0 TRUE TRUE FALSE "0" TRUE TRUE FALSE "" TRUE TRUE FALSE " " FALSE TRUE FALSE NULL TRUE FALSE TRUE FALSE TRUE TRUE FALSE array() TRUE TRUE FALSE Link to comment https://forums.phpfreaks.com/topic/259474-how-can-i-check-if-associate-array-element-is-empty-or-not/#findComment-1330113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.