Reputation: 1883
I show number of items in a cookie
with:
if(isset($_COOKIE['Bookmark'])) {
$sAds = explode(",",$_COOKIE['Bookmark']);
$countSAds = sizeof($sAds);
$savedAds = '<span>'.$countSAds.'</span>';
} else {
$savedAds = '';
}
And in html
:
echo $savedAds; // output: <span>3</span>
Also sample data of cookie:
252,190,210
This is return 3
.
But if there is no bookmark (item) set in cookie, it show 1
, when there is nothing in this cookie, it return 0
so by sizeof
it return 1
because it count number of array
, how can I count cookie items if it is empty and should return 0
Example:
sample data is nothing, I mean nothing in cookie, code return <span>1</span>
but I want to show 0
Upvotes: 0
Views: 220