Jump to content

php function for strlen in array?


solarisuser

Recommended Posts

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

 

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.