NULL and 0 - 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: NULL and 0 (/showthread.php?tid=29872) Pages:
1
2
|
NULL and 0 - El Forum - 04-24-2010 [eluser]dimaomni[/eluser] Hello everybody! I have some input_form().From they I receive array which can include key with digits and empty values. This values I use for INSERT query, and when value has NULL - this involve sql error. So I start to use array_filter(), and everything had been good before I needed use "0". I've tried use this condition, however it like tautology and don't work ). Code: if ($mark>=0 && $mark<=12 && $mark != NULL) What do you tell ? NULL and 0 - El Forum - 04-24-2010 [eluser]Tominator[/eluser] Hi! Try this: Code: if((!empty($mark) || $mark == 0) && $mark <= 12 && !($mark < 0)) Tom. NULL and 0 - El Forum - 04-24-2010 [eluser]Krzemo[/eluser] empty will return true both for 0 and null two possibilites: 1. if value is null change it to something acceptable Code: foreach($arr as $val) regs NULL and 0 - El Forum - 04-24-2010 [eluser]EmmaMadeleine[/eluser] thnxx Tominator NULL and 0 - El Forum - 04-25-2010 [eluser]Tominator[/eluser] More effective: Code: if((!empty($mark) || $mark == '0') && $mark <= 12 && !($mark < 0)) Cshamoh: Empty will not return true for 0 or null NULL and 0 - El Forum - 04-25-2010 [eluser]Krzemo[/eluser] Taken from PHP manual: Quote:The following things are considered to be empty: So IMHO empty will return true both when 0 and NULL NULL and 0 - El Forum - 04-25-2010 [eluser]Tominator[/eluser] Oh I am sorry I thought about !empty D Yes, 0 and NULL will return true (it is empty), but I am using !empty and my script was tested Sorry to you Cshamoh, I was wrong ... Tom. NULL and 0 - El Forum - 04-25-2010 [eluser]dimaomni[/eluser] I've tried test with simpler code Code: <?php b b 0 b b ---------------------- Code: $a = array("1"=>'',"2"=>0,"3"=>4,"4"=>'',"5"=>NULL); b b 0 b b ------------------- Code: <?php result b 0 ----------------- Code: <?php result b 0 b 4 ---------- lsat code works but in project still not work, I've asked a teacher and he gave solution: Code: if (preg_match("!^([0-9]|1[1-2])$!", $b) so it works everywhere. NULL and 0 - El Forum - 04-25-2010 [eluser]Tominator[/eluser] Have you tried my condition? Because it's faster than regexp (and works everywhere too) NULL and 0 - El Forum - 04-25-2010 [eluser]dimaomni[/eluser] [quote author="Tominator" date="1272246124"]Have you tried my condition? Because it's faster than regexp (and works everywhere too) [/quote] At first I've tried in work example and it didn't. Just now I tried in simple code and it work. Miracles aren't. Miracle-workers are. :-) Need to look carefully to code. I think topic have to be close. Very thanks for all!!! |