1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Lenght of strings in an array!

Discussion in 'PHP' started by Justcrapx, Nov 25, 2006.

  1. Justcrapx

    Justcrapx New Member

    Joined:
    Oct 30, 2006
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Simple! Here is the code!

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

Share This Page