Make a function that will accept any array of 3 positions and print all possible combinations of its elements. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Make a function that will accept any array of 3 positions and print all possible combinations of its elements.

can someone help me with the following Make a function that will accept any array of 3 positions and print all possible combinations of its elements. Example: Suppose we have: $ array = [red, blue, green] Based on the above array, the output will be: red blue green red blue red green blue green red blue green

8th Feb 2021, 10:30 AM
Giorgos Krinis
Giorgos Krinis - avatar
3 Answers
+ 1
Show your attempt first, please. We will fix it.
8th Feb 2021, 10:37 AM
#0009e7 [get]
#0009e7 [get] - avatar
+ 1
I wrote this to show me the original table $colors=['red','blue','green']; for($i=0;$i<count($colors);$i++){ echo '<ul><li>'.$colors[$i].'</li></ul>'; } for($i=2;$i<count($colors);$i++){ echo '<ul><li>'.$colors[0].' '.$colors[1].'</li></ul>'; echo '<ul><li>'.$colors[0].' '.$colors[2].'</li></ul>'; echo '<ul><li>'.$colors[1].' '.$colors[2].'</li></ul>'; } i have stuck. when i try to enter in function i take errors and and I do not know if the second code I wrote is spelled correctly
8th Feb 2021, 11:15 AM
Giorgos Krinis
Giorgos Krinis - avatar
+ 1
I fix it!!!
10th Feb 2021, 8:16 PM
Giorgos Krinis
Giorgos Krinis - avatar