Skip to content
Omni Academy
Search courses and lessons
Search
Courses
Backend Development
9
Databases
1
Frontend Development
5
Data Science
5
All courses →
Playground
HTML & CSS
JavaScript
TypeScript
Python
PHP
Ruby
Light
Dark
Auto
Sign in
Get started
All
Backend Development
Databases
Frontend Development
Data Science
Playground
Blog
HTML
JS
TS
PY
PHP
RB
← Courses
📄
Strings and arrays
Run as I type
Reset
▶
Run
Ctrl
↵
PHP
PHP source code
<?php $text = "the quick brown fox jumps over the lazy dog"; echo ucwords($text), "\n"; echo str_word_count($text), " words, ", strlen($text), " characters\n\n"; // explode splits, implode joins. Neither changes the original. $words = explode(" ", $text); $long = array_filter($words, fn($w) => strlen($w) > 4); echo "Longer than four letters: ", implode(", ", $long), "\n"; // array_map keeps the keys out of the way; array_reduce folds. $lengths = array_map("strlen", $words); echo "Total letters: ", array_reduce($lengths, fn($c, $n) => $c + $n, 0), "\n\n"; // Sorting needs to be told what to compare. usort($words, fn($a, $b) => strlen($b) <=> strlen($a)); echo "Longest: ", $words[0], "\n";
Input
one line per
input()
call
Output
Rendered by your browser