Count the number of vowels in an array in PHP

Shulz

In PHP I have written a script to count the number of vowels in an array and output the result.

When running the script I get an Undefined offset error.

What is wrong with this code?

for($a = 0; $a < count($expld); $a++) {
    for($b = 0; $b < strlen($expld[$b]); $b++) {
        if ($expld[$b] == 'A' || $expld[$b] == 'a' || $expld[$b] == 'E' || $expld[$b] == 'e'
            || $expld[$b] == 'I' || $expld[$b] == 'i' || $expld[$b] == 'O' || $expld[$b] == 'o'
            || $expld[$b] == 'U' || $expld[$b] == 'u')
        {
            $vowel++;
        }
    }
    echo "$expld[$a] has $vowel vowels(s).<br> ";
}
mcserep

It seems you quite messed up the indexing, check it out:

for($a = 0; $a < count($expld); $a++)
{
    $vowel = 0;
    for($b = 0; $b < strlen($expld[$a]); $b++)
    {
        if($expld[$a][$b] == 'A' || $expld[$a][$b] == 'a' || $expld[$a][$b] == 'E' || $expld[$a][$b] == 'e'
        || $expld[$a][$b] == 'I' || $expld[$a][$b] == 'i' || $expld[$a][$b] == 'O' || $expld[$a][$b] == 'o'
        || $expld[$a][$b] == 'U' || $expld[$a][$b] == 'u')
        {
          $vowel++;
        }
    }
    echo "$expld[$a] has $vowel vowels(s).<br> ";
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Count the number of vowels in an array in PHP

From Dev

Count number of a group array in array in php

From Dev

PHP Multidimensional Array - Count Number of Instances

From Dev

Count number of times a word appears in php array

From Dev

PHP - Best way to count the number of things in array

From Dev

Count the number of vowels and print them in a manner that string having more vowels come first

From Dev

Count vowels in a word

From Dev

Count specific vowels in a sentence

From Dev

PHP Count Number of Times A String Appears As A Value Inside An Array

From Dev

Count the number of times an index is a specific name in an array php

From Dev

How to count number of elements of a multidimensional array without using loop in PHP?

From Dev

PHP Count Number of Times A String Appears As A Value Inside An Array

From Dev

Count number of elements in array

From Dev

Count number of elements in an array

From Dev

Count number of ocurrences in an array

From Dev

Greatest number of consecutive vowels

From Dev

Method miscalculates number of vowels

From Dev

JAVA: I have to write a program to read "sentences" from a file and and then count the number of words and vowels per sentence

From Java

Counting vowels in an array

From Dev

Printing the vowels and the vowel count in a string

From Dev

How to count the number of times an array value is repeated in another array element using PHP?

From Dev

Create new array from two array in with i will count the number of occurence some values in php

From Dev

PHP Count Array Columns

From Dev

PHP count JSON array

From Dev

count element in array php

From Dev

Count the number of same values in array

From Dev

Jquery Count number of occurances in array

From Dev

Count number of ones in a array of characters

From Dev

count number of events in an array python

Related Related

  1. 1

    Count the number of vowels in an array in PHP

  2. 2

    Count number of a group array in array in php

  3. 3

    PHP Multidimensional Array - Count Number of Instances

  4. 4

    Count number of times a word appears in php array

  5. 5

    PHP - Best way to count the number of things in array

  6. 6

    Count the number of vowels and print them in a manner that string having more vowels come first

  7. 7

    Count vowels in a word

  8. 8

    Count specific vowels in a sentence

  9. 9

    PHP Count Number of Times A String Appears As A Value Inside An Array

  10. 10

    Count the number of times an index is a specific name in an array php

  11. 11

    How to count number of elements of a multidimensional array without using loop in PHP?

  12. 12

    PHP Count Number of Times A String Appears As A Value Inside An Array

  13. 13

    Count number of elements in array

  14. 14

    Count number of elements in an array

  15. 15

    Count number of ocurrences in an array

  16. 16

    Greatest number of consecutive vowels

  17. 17

    Method miscalculates number of vowels

  18. 18

    JAVA: I have to write a program to read "sentences" from a file and and then count the number of words and vowels per sentence

  19. 19

    Counting vowels in an array

  20. 20

    Printing the vowels and the vowel count in a string

  21. 21

    How to count the number of times an array value is repeated in another array element using PHP?

  22. 22

    Create new array from two array in with i will count the number of occurence some values in php

  23. 23

    PHP Count Array Columns

  24. 24

    PHP count JSON array

  25. 25

    count element in array php

  26. 26

    Count the number of same values in array

  27. 27

    Jquery Count number of occurances in array

  28. 28

    Count number of ones in a array of characters

  29. 29

    count number of events in an array python

HotTag

Archive