I'm having some issues using the serialize
and unserialize
PHP function as it relates to boolean data.
If I serialize
this array:
$test = [
"id" => "test",
"name" => "Test",
"isActive" => 0
];
$data = serialize($test);
And then unserialize
it:
$data = unserialize($data);
This is the array I am seeing:
$data = [
"id" => "test",
"name" => "Test",
"isActive" => "0"
];
It has converted the boolean property to a string. Any ideas on how to keep that property in tact?
I read that serialize
and unserialize
do not recognize true/false.
My Answer:
'is_true' => true,_ 'is_false' => false,_];_and then unserialize it:_$serialized = serialize($test);$unserialized = unserialize($serialized);_I would expect the 'is_true' key to have a value of true and the 'is_false' key to have a value of false. However, when I print out the unserialized array, both values are converted to 1 (true)._Is there a way to properly serialize and unserialize boolean data in PHP?
Rate this post
4 of 5 based on 1283 votesComments