count of empty array |
[eluser]PHPraja[/eluser]
when i try to get the count of empty array which is posted from a form, I get the count as 1. Actually the count should be zero. Is nt it? Any one faced such problem?
[eluser]Hermawan Haryanto[/eluser]
Are you sure that it's an array? Take a look at this manual here: http://id.php.net/count If var is not an array or an object with implemented Countable interface, 1 will be returned. There is one exception, if var is NULL, 0 will be returned. Good luck, Hermawan Haryanto
[eluser]andreagam[/eluser]
Depending on the formulation, you could be getting a nested array, that is an array of arrays... If so you could try counting the size of arrayname[0] to see if it's really empty.
[eluser]gtech[/eluser]
you could always try print_r($array_or_obj_name); then you will know the contents.
[eluser]PHPraja[/eluser]
Actually i got this count of empty array while validations using call back functions. In my 'EmailToFriend' view i have a message box(text area), some list of dynamic check boxes(Friends list) and a textarea where the user can enter his friends emailid with a comma separated. Before submitting the form we should validate such that atleast one checkbox is checked or atleast one emailid is entered in the textarea. for this i used a CI validation as below using callback function. Code: $rules['emailslist']="callback_emailslist_check"; In the above code 'emailslist' is the name of the textarea where the emailids should be entered and 'chkEmails' is the dynamic array (checkbox name ) This call back function does nt work. In the callback function can i check combination of two fields for validation? as i used above. I hope the above explanation is clear to express my doubt. any one plz help..
[eluser]Seppo[/eluser]
Try this if((is_array($this->input->post('chkEmails')) && count($this->input->post('chkEmails'))==1 ) && ($e=='')) |
Welcome Guest, Not a member yet? Register Sign In |