The str_word_count function counts the number of words in a string.

    
    $sentence = 'The quick brown fox';

    $sentenceWordCount = str_word_count($sentence);

    echo $sentenceWordCount;
    // 4