Split the string $str = '12,34,5'; Split it into an array $arr = [[1,3,5],[1,4,5],[2,3,5 ],[2,4,5]]; Looking for a PHP logical algorithm to convert $str to $arr;
Explain that using global may not look that elegant, but here I am just writing an example method. If it is not too confusing, you can optimize it by yourself
Two arrays are easy to combine. Two nested for loops are enough. A multiarray with an uncertain number cannot be processed in this way. You can refer to some sorting algorithm ideas. The multiarray is converted into two through recursion. Array, such as: [[1,2],[3,4],[5]], convert it to [[13,14,23,24],[5]], the last two nested for loops Solution, reference code:
Explain that using global may not look that elegant, but here I am just writing an example method. If it is not too confusing, you can optimize it by yourself
Two arrays are easy to combine. Two nested for loops are enough. A multiarray with an uncertain number cannot be processed in this way. You can refer to some sorting algorithm ideas. The multiarray is converted into two through recursion. Array, such as: [[1,2],[3,4],[5]], convert it to [[13,14,23,24],[5]], the last two nested for loops Solution, reference code: