I have a variable holding values separated by a comma (Implode), and I’m trying to get the total count of the values in that variable. However. count() is just returning 1.
I’ve tried converting the comma-separated values to a properly formatted array which still spits out1.
So here is the quick snippet where the sarray session is equal to value1,value2,value3:
$schools = $_SESSION['sarray'];
$result = count($schools);
You need to explode
$schoolsinto an actual array:if you just need the count, and are 100% sure it’s a clean comma separated list, you could also use substr_count() which may be marginally faster and, more importantly, easier on memory with very large sets of data: