3 ms·
<?php $string = "aeiouxabcd"; $checkfor = array('a','e','i','o','u'); $count = 0; for($x = 0; $x < strlen($string); $x++) { if(in_array($string[$x
by pixeloution 15y ago
<?php
$string = "aeiouxabcd";
$checkfor = array('a','e','i','o','u');
$count = 0;
for($x = 0; $x < strlen($string); $x++) {
if(in_array($string[$x], $checkfor)) {
$count++;
}
}
echo $count . "\n";
Am I hired? Or do I lose cool points for PHP?
- woogley 15y ago<?php echo strlen(preg_replace('/[^aeiou]/i', '', 'hello world'));
- deleted 15y ago[deleted]
- patio11 15y agoEvery time FizzBuzz problems come up among engineers, people race to solve them and post their answers, then compete to see who can write increasingly more nifty answers for a question which does not seek niftiness at all. I'm all for intellectual gamesmanship, but these are our professional equivalent of a doctor being asked to identify the difference between blood and water. You can do it. We know. Demonstrating that you can do it is not the point of the exercise. We do it to have a cheap-to-administer test to exclude people-who-cannot-actually-program-despite-previous-job-titles from the expensive portions of the hiring process.
- peteretep 15y agoYou lose the cool points for not using a regex, I'm afraid.