Welcome Guest, Not a member yet? Register   Sign In
How to determine if input->post item does exist, but is zero?
#1

[eluser]warpspasm[/eluser]
Hi Everyone,

According to the Codeigniter documentation:

$this->input->post('some_data');
The function returns FALSE (boolean) if the item you are attempting to retrieve does not exist.

But what if I want to know if the value does exist, but is zero?

Please let me know if you know how I could determine this?

Thanks
#2

[eluser]warpspasm[/eluser]
...such a shame this function doesn't return null if the item doesn't exist. Or am I missing some reason as to why false was a better choice?
#3

[eluser]jairoh_[/eluser]
Code:
if ( $this->input->post(‘some_data’) == false ) or if ( $this->input->post(‘some_data’) == 0 ) or if ( !$this->input->post(‘some_data’) )
#4

[eluser]warpspasm[/eluser]
[quote author="jairoh_" date="1371336633"]
Code:
if ( $this->input->post(‘some_data’) == false ) or if ( $this->input->post(‘some_data’) == 0 ) or if ( !$this->input->post(‘some_data’) )
[/quote]

The problem with this code is that if:

$this->input->post('some_data') == 0;

or

$this->input->post('some_data') doesn't exist;

You still get false back from the function. I'm looking for a way to be sure that $this->input->post('some_data') is set AND and that it is set to 0.

Does that make sense?
#5

[eluser]CroNiX[/eluser]
=== operator so it will check the datatype too, not ==
Code:
if ($this->input->post(‘some_data’) === 0)
#6

[eluser]warpspasm[/eluser]
Thanks Cronix, I think that will do the job perfectly! You da man.




Theme © iAndrew 2016 - Forum software by © MyBB