How can php generate rules faster (combination)

question: rules need to be generated according to some conditions, for example, there are 3 areas (area A, B, C) and three streets (A Street, B Street, C Street), then there will be 9 rules generated, as follows:

1A area A street
2A area B street
3A area C street

4 B area A Street
5 B area B Street
6 B area C Street

7 C area A Street
8 C area B Street
9 C area C Street

above are the 9 generated rules,

is there anything else you can do but nested loops, gods?

if there are more conditions to generate, then the nested loop estimation is not good, it is too tedious.

Php
Jul.22,2021

learn about it recursively

write a simple one

  

I went to look at the function in laravel that calculates Cartesian product, and it still seems to be a nested loop at the bottom!

Menu