solarisuser Posted February 22, 2008 Share Posted February 22, 2008 Hi All, I have data in an array like this "12345, 56789, KL5-1231231,KL5-1230502". Is there a function that I can use to say.... if string length of each piece of the array is less than 6, put it in this array, and the rest of the data entries go in another array. For example: $original_array = ("12345", "56789", "KL5-1231231","KL5-1230502"); some_function_here... $array1 = ("12345", "56789"); $array2 = ("KL5-1231231","KL5-1230502"); Thanks Quote Link to comment Share on other sites More sharing options...
drisate Posted February 22, 2008 Share Posted February 22, 2008 you can convert your aray to a string then explode by every (,) and loop using foreach Quote Link to comment Share on other sites More sharing options...
duclet Posted February 22, 2008 Share Posted February 22, 2008 You don't really need a function. Couldn't you do something like the following: <?php $original_array = ("12345", "56789", "KL5-1231231","KL5-1230502"); $array1 = array(); $array2 = array(); foreach($original_array as $item) { if(isset($item[6])) { $array1[] = $item; } else { $array2[] = $item; } } ?> Of course you can use strlen($item) < 6 instead of what I have in the if statement but I like my way since it is a little faster. Quote Link to comment Share on other sites More sharing options...
solarisuser Posted February 22, 2008 Author Share Posted February 22, 2008 very cool , thanks. i was looking for something not using strlen and tons of if statements... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.