-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.php
More file actions
28 lines (22 loc) · 713 Bytes
/
string.php
File metadata and controls
28 lines (22 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
// Input array of strings
$strings = ["Hello", "World", "PHP", "Programming"];
// Function to count vowels in a string
function countVowels($string) {
$vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'];
$count = 0;
for ($i = 0; $i < strlen($string); $i++) {
if (in_array($string[$i], $vowels)) {
$count++;
}
}
return $count;
}
// Process each string in the array
foreach ($strings as $string) {
$vowelCount = countVowels($string); // Count vowels
$reversedString = strrev($string); // Reverse the string
// Print the result
echo "Original String: $string, Vowel Count: $vowelCount, Reversed String: $reversedString <br>";
}
?>