I have following PHP array:
$array = array( 'uname', '=', 'lizabd', 'pass', '=', '225555')
now I want to loop every 3 element like this way
uname = lizabd
pass = 225555
How can I do this?
I know I can slice it using this for the first element:
$slice = array_slice($array, 3);
But how can I do this using Loop ?
You need to use array_chunk()
$array = array_chunk($array,3);
foreach($array as $arr){
echo implode(' ',$arr);
echo PHP_EOL; //for new line, you can also use echo '<br>';
}
Output:- https://eval.in/970842
Reference:- implode()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With