Q:

Write a PHP program to count the number of strings with given length in given array of strings

0

Write a PHP program to count the number of strings with given length in given array of strings

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function test($arr_str, $len)
    { 
        $ctr = 0;

        for ( $i = 0;  $i < sizeof($arr_str);  $i++)
            {
                if (strlen($arr_str[$i]) ==  $len)  $ctr++;
            }
            return  $ctr;
    }
    

echo test(["a", "b", "bb", "c", "ccc"], 1)."\n";

Sample Output:

3

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now