The database stores records (user’s friends) in the form:

qwerty1,qwerty2 

This is an array that stores users. How to count the number of users in it?

    2 answers 2

    You can try this:

     $friends = "f1,f2,f3"; $countFriends = count(explode(',', $friends)); echo $countFriends; 
    • it was this option that I used - LLIAKAJI
    • one
      @LLIAKAJI, there is a button on the left to accept the answer - etki

    It is possible this way: we have a line separated by commas, so the number of words is the number of commas + 1

    Here is the implementation

     len(value) - len(replace(value,',','')) + 1 
    • Fatal error: Call to undefined function len () - LLIAKAJI
    • @LLIAKAJI - oh .., well, from the context it is clear that we are talking about [strlen ()] [1] [1]: php.net/manual/ru/function.strlen.php - Opalosolo
    • The problem was solved in the following way: variable = explode (',', value); echo count (variable); - LLIAKAJI