I've an array that contains data taken by splitting a string.
Mike,20,male,Ann,28,female,chuck,45,male
$people = explode(',', $result);
how can I assign these data in the array 3 by 3 into 3 different variables using foreach?
Mike 20 male
and then
Ann 28 female
then
chuck 45 male
foreach(array_chunk(explode(',', $result), 3) as $row) {
list($name, $age, $gender) = $row;
}
actually, even better:
foreach(array_chunk(explode(',', $result), 3) as list($name, $age, $gender)) {
}
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