• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Storing "0" Zero in a session as a variable

I am pretty sure i know why this is occurring - but just wondered if there are any gotchas around this?

I have a form that submits a number of scored answers values 0-9. These values are then held in a session for a couple of screen where further questions are asked, until finally something is done with them at the end...

All numbers store and work fine... except "0". This gets submitted to the form, but when added in the session, and viewing the session data nothing is there. Now i assume this is because "0" is nothing, and is seen as null or false... But i need to see that "0" for scoring purposes where i add up the values.

So is there some stupid gotcha that i am not thinking about here, or is CI filtering it out on my behalf i a need to change a setting, or any obvious ways that this should be handled that i as a non programmer should really know about?

Thanks, N

I should add that i need the "0" for referencing an array key - hence i need the "0".


Post the code where you save the '0' value in the session and validation rules if any.
Without code itś rather hard to see why or how.

Hi Roger,
Thanks for your reply - i must admit i was assuming that CI was filtering the values before putting them into the session. However, after the above post and digging through the code and functions i was provided from the previous developer i found it to be a bit of sloppy code that runs an if statement on the value while prepping it. As such of course 0 will be identified as false, hence no value.

Thanks for the reply anyhow. I should have hit the debugging first, rather than trust supplied code!

This might be a little bit late, but there are differences among the following:


if($something = TRUE){...}

if($something == TRUE){...}

if($something === TRUE){...}

The last one is the one preferred to avoid any ambiguity.


Hi Attos,
Yeah this basically is the method to resolve it, there are some pretty good tables and charts out there defining what passes and fails these checks - some not as obvious as others!

After all this the client has changed their mind again anyway - so another method is going to be needed, so i can happily rewrite the bits i did not like from the provided code!
Thanks, N

Nothing better than your own code.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.