# \[php\] Array element combinations... It needs recursion and it's too hard for me!

**URL:** <https://forum.kirupa.com/t/php-array-element-combinations-it-needs-recursion-and-its-too-hard-for-me/187467>\
**Category:** programming\
**Created:** [April 29, 2006, 12:41pm UTC](https://forum.kirupa.com/t/php-array-element-combinations-it-needs-recursion-and-its-too-hard-for-me/187467 "2006-04-29T12:41:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![maurits](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@maurits](https://forum.kirupa.com/u/maurits)\
**Post date:** [April 29, 2006, 12:41pm UTC](https://forum.kirupa.com/t/php-array-element-combinations-it-needs-recursion-and-its-too-hard-for-me/187467/1 "2006-04-29T12:41:00Z")

</div>

Hello guys!

Assume an arbitrary number of arrays, like so:

```php
$color = array("blue", "green", "yellow");
$size = array("small", "large");
$weight = array("light", "medium", "heavy");

```

What I want to do is find all the possible unique element combinations between the elements of these arrays. Think of a car that is blue, small and light, or blue, small and heavy. This is what works for three arrays:

```php
function arrays_mix(){

	$args = func_get_args();
	
	foreach($args[0] as $value[0]){

		foreach($args[1] as $value[1]){
		
			foreach($args[2] as $value[2]){
			
				$combinations[] = implode(", ",$value);
				
			}
		}
	}

	return $combinations;

}

/*

 	Output:

	Array
	(
		[0] => blue, small, light
		[1] => blue, small, medium
		[2] => blue, small, heavy
		...
		[17] => yellow, large, heavy
	)
*/

```

Obviously, I want to accept an arbitrary number of arguments. I am certain that recursion is the answer and I’ve tried a lot of things that just don’t work. Can you guys help me out? I am definitely stuck right now.
