my string has
$string = "apple,banana,orange,lemon";
I want to as
$array = [
[apple,banana],
[orange,lemon]
]
my string has
$string = "apple,banana,orange,lemon";
I want to as
$array = [
[apple,banana],
[orange,lemon]
]
2
Answers
I hope this helps you get on your way. To transform a string to an array, you can use
This will leave you with this array:
($elements == [apple,banana,orange,apple])
From there, you can build it the way you want, like:
This results in the array you are looking for, but this solution is only for the string you’ve given with four elements, separated by comma.
Use array_chunk in combination with explode defined in php https://www.php.net/manual/en/function.array-chunk.php
Will output as below: