PHP Coding Practice
Practice typing real code syntax, including brackets, punctuation, and indentation. Snippets are for typing practice only and are never executed.
Functions, arrays, and loops
Type the code exactly. Tab inserts four spaces. Code is not executed.
Progress: 0%
Current mismatches: 0
<?php
declare(strict_types=1);
function formatName(string $name): string
{
return trim($name);
}
$names = ['Ada', 'Grace'];
$formattedNames = array_map('formatName', $names);
foreach ($formattedNames as $name) {
echo $name . PHP_EOL;
}
Type the code exactly, including spaces and indentation.