How can I explode a string at the position after every third semicolon (;)?
example data:
$string = 'piece1;piece2;piece3;piece4;piece5;piece6;piece7;piece8;';
Desired output:
$output[0] = 'piece1;piece2:piece3;'
$output[1] = 'piece4;piece5;piece6;'
$output[2] = 'piece7;piece8;'
Notice the trailing semicolons are retained.
create_function()
is bad practive). Starting from PHP 5.3 you can use a lambda function for it, though:$output = array_map(function($a) { return implode(';', $a); }, $chunks);
– Supernormal