How do I count comma-separated values in PHP?

前端 未结 5 517
青春惊慌失措
青春惊慌失措 2020-12-11 05:06

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.

5条回答
  •  有刺的猬
    2020-12-11 05:39

    $schools = $_SESSION['sarray'];
    $array = explode(',', $schools); array_walk($array, 'trim');
    $count = count($array);
    

    The array_walk($array, 'trim') will remove any trailing space in elements value. :)

提交回复
热议问题