I have a line like:
12121212
I want to get only 1111, the first letter, then the third, then the fifth ... one letter in two.
Is there any function for this? I use str_split, then take the first letter of my array, but this is not very clean. Thanks.
This is my code at the moment, but it is not very flexible:
function loop_n_letter($string, $n) { $return = ''; $array = str_split($string); foreach ($array as $i => $row) { if ($i % $n == 0) { $return .= $row[0]; } } return $return; }
source share