Jump to content

pseudo code assistance


Recommended Posts

this is what i have

 

$vowels = array('a','e','i','o','u');
$string = 'An example string';
$length = strlen($string);
$count = 0;
for ($i = 0; $i !== $length; $i++ { 
if (array_search($length[$i], $vowels)) { 
$count++;

}

}
echo 'There are (' . $count . ') vowels in the sentense(' . $string . ').';

  • 4 weeks later...

since you tried (and almost had it) here's a similar way to do it:

<?php
$vowels = array('a','e','i','o','u');
$string = 'An example string';
// split string into array, make all lowercase (or I would have to add uppercase vowels to $vowels)
$parts = str_split(strtolower($string));
$count = 0;
foreach ($parts as $letter) {
if (in_array($letter, $vowels)) $count++;
}
echo 'There are (' . $count . ') vowels in the sentence (' . $string . ').';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.