Lenght of strings in an array!

Justcrapx's Avatar
Light Poster
Can someone gimme the idea to check if any string elements of an array are longer than "x" characters.

In other words, pretend that theres an array which we dont know how many elements it has. And this array only keeps strings. All i want is a code that returns false if theres any long string than 20.
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Simple! Here is the code!

PHP Code:
<?
 function check_array_string(&$arr,$length=10)
 {
     foreach($arr as $v)
         if(strlen($v)>$length)
             return false;
     return true;
 }
 ?>
Example:
PHP Code:
$a = ["sas","aasew","wewr"];
check_array_string($a,20);