justcrapx Posted November 25, 2006 Share Posted November 25, 2006 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 More sharing options...
JasonLewis Posted November 25, 2006 Share Posted November 25, 2006 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... Link to comment https://forums.phpfreaks.com/topic/28418-lenght-of-strings-in-an-array/#findComment-130014 Share on other sites More sharing options...
justcrapx Posted November 25, 2006 Author Share Posted November 25, 2006 Works great for me. Thankz =))) Link to comment https://forums.phpfreaks.com/topic/28418-lenght-of-strings-in-an-array/#findComment-130020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.