Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   Lenght of strings in an array! (http://www.go4expert.com/forums/lenght-strings-array-t1996/)

Justcrapx 25Nov2006 15:10

Lenght of strings in an array!
 
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 27Nov2006 12:56

Re: Lenght of strings in an array!
 
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); 



All times are GMT +5.5. The time now is 14:54.