Lenght of strings in an array!

Light Poster
25Nov2006,15:10   #1
Justcrapx's Avatar
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.
Team Leader
27Nov2006,12:56   #2
pradeep's Avatar
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);