Page 1 of 1
serialize function trouble
Posted: Thu Mar 03, 2011 6:14 pm
by Ralphy
I hope you guys can help me, Im getting serialized values from a database field but if the field is empty, the unserialized array returns 1 with the count function when it should be 0.
Anyone have any ideas?
Re: serialize function trouble
Posted: Thu Mar 03, 2011 6:53 pm
by greyhoundcode
Per the manual:
PHP wrote:If var is not an array or an object with implemented Countable interface, 1 will be returned. There is one exception, if var is NULL, 0 will be returned.
So if for example your field is basically an empty string then this is expected behaviour, and is not a problem resulting from the
unserialize() function. You might want to change the conditions of your test.
Code: Select all
if (count($result) == 0 || empty($result))
{
// Empty field / no elements in the array
}