![]() |
count of empty array - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: count of empty array (/showthread.php?tid=8170) |
count of empty array - El Forum - 05-08-2008 [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? count of empty array - El Forum - 05-08-2008 [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 count of empty array - El Forum - 05-08-2008 [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. count of empty array - El Forum - 05-08-2008 [eluser]gtech[/eluser] you could always try print_r($array_or_obj_name); then you will know the contents. count of empty array - El Forum - 05-08-2008 [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.. count of empty array - El Forum - 05-08-2008 [eluser]Seppo[/eluser] Try this if((is_array($this->input->post('chkEmails')) && count($this->input->post('chkEmails'))==1 ) && ($e=='')) |