- var_dump: documentation ( source)
- str_split: documentation ( source)
<?php
$x = 'Hi Nemo';
function solution (string $str)
{
foreach(str_split($str) as $wordNum => $value) {
if ($value === 'Nemo') {
return "I found Nemo at $wordNum";
}
}
return 'I can\'t found Nemo';
}
var_dump(solution($x));