Jump to content

Lenght of strings in an array!


justcrapx

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/28418-lenght-of-strings-in-an-array/
Share on other sites

well...i dont no any quick ways but you could do something like this:

[code=php:0]
$max_chars = 20;
$array = array("astring", "astringthatislonger", "string", "stringagain");

$found_errors = 0;
foreach($array as $value){
if(strlen($value) > $max_chars){
$found_errors++;
}
}

if($found_errors > 0){
return false;
}else{
return true;
}
[/code]

think that would work. there might be a quick function...i dont no...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.