Tsallaka zuwa abun ciki
Justice Tech School

Practice: Word Counter

Combine strings and arrays to count words.

Example
$text = "the cat and the hat";
$words = explode(" ", $text);
$counts = array_count_values($words);
arsort($counts);
print_r($counts);

Result

Array
(
    [the] => 2
    [cat] => 1
    [and] => 1
    [hat] => 1
)

Exercise

Split on space.

(" ", $text)

Quiz Test

Which counts values?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.