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? Quote 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 } Quote 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? Quote 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 Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.