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?
serialize function trouble
Moderator: General Moderators
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: serialize function trouble
Per the manual:
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.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.
Code: Select all
if (count($result) == 0 || empty($result))
{
// Empty field / no elements in the array
}