Reputation: 1244
I want to store in a MySql tinyint(1)
field values that i have already converted from boolean
with php's intval()
.
Example:
$data = true;
$foo = intval($data);
if (is_numeric($foo)){
print_r($foo);
}
The problem is that even if the $data
is true
and the $foo
is numeric, intval
always returns 0
.
Update:
I have this jQuery code in order to take true/false
if an html
checkbox is checked.
var foo = $('#' + form + ' ' + '[name = "foo"]').is(':checked');
then i'm sending the variable foo
to my controller: (The jQuery code works correctly)
$foo = Input::has('foo') ? Input::get('foo'): false;
$newFoo = New Foo();
$newFoo->foo=$foo;
Finally in my class:
public $foo;
print_r(intval($this->foo));
Upvotes: 0
Views: 1448
Reputation: 1806
Because your $data
is a string not boolean. You can cast it first and should work
Upvotes: 1