Yngvarr

Generation

generate functionThu, 09 Feb 2023

разбить строку по 5 символов

function splitStringBy5Char($string) { $result = []; $currentString = ''; for ($i = 0; $i < strlen($string); $i++) { $currentString .= $string[$i]; if (strlen($currentString) >= 5) { $result[] = $currentString; $currentString = ''; } } if ($currentString) $result[] = $currentString; return $result; } print_r(splitStringBy5Char('1234567890'));

Questions about programming?Chat with your personal AI assistant