3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $products = [1, 2, 3, 4, 5]; $vendors = ["Amazon", "Newegg", "Frys"]; $combinations = array(''); function pc_permute($items, $perms = array()) { if (empty($items)) { echo join(' ', $perms) . "</br>"; //return $perms; //array_push($combinations, $perms); } else { for ($i = count($items) - 1; $i >= 0; --$i) { $newitems = $items; $newperms = $perms; list($foo) = array_splice($newitems, $i, 1); array_unshift($newperms, $foo); pc_permute($newitems, $newperms); } } } pc_permute($products); var_dump($combinations);
Output for 5.4.0 - 7.1.0
1 2 3 4 5</br>2 1 3 4 5</br>1 3 2 4 5</br>3 1 2 4 5</br>2 3 1 4 5</br>3 2 1 4 5</br>1 2 4 3 5</br>2 1 4 3 5</br>1 4 2 3 5</br>4 1 2 3 5</br>2 4 1 3 5</br>4 2 1 3 5</br>1 3 4 2 5</br>3 1 4 2 5</br>1 4 3 2 5</br>4 1 3 2 5</br>3 4 1 2 5</br>4 3 1 2 5</br>2 3 4 1 5</br>3 2 4 1 5</br>2 4 3 1 5</br>4 2 3 1 5</br>3 4 2 1 5</br>4 3 2 1 5</br>1 2 3 5 4</br>2 1 3 5 4</br>1 3 2 5 4</br>3 1 2 5 4</br>2 3 1 5 4</br>3 2 1 5 4</br>1 2 5 3 4</br>2 1 5 3 4</br>1 5 2 3 4</br>5 1 2 3 4</br>2 5 1 3 4</br>5 2 1 3 4</br>1 3 5 2 4</br>3 1 5 2 4</br>1 5 3 2 4</br>5 1 3 2 4</br>3 5 1 2 4</br>5 3 1 2 4</br>2 3 5 1 4</br>3 2 5 1 4</br>2 5 3 1 4</br>5 2 3 1 4</br>3 5 2 1 4</br>5 3 2 1 4</br>1 2 4 5 3</br>2 1 4 5 3</br>1 4 2 5 3</br>4 1 2 5 3</br>2 4 1 5 3</br>4 2 1 5 3</br>1 2 5 4 3</br>2 1 5 4 3</br>1 5 2 4 3</br>5 1 2 4 3</br>2 5 1 4 3</br>5 2 1 4 3</br>1 4 5 2 3</br>4 1 5 2 3</br>1 5 4 2 3</br>5 1 4 2 3</br>4 5 1 2 3</br>5 4 1 2 3</br>2 4 5 1 3</br>4 2 5 1 3</br>2 5 4 1 3</br>5 2 4 1 3</br>4 5 2 1 3</br>5 4 2 1 3</br>1 3 4 5 2</br>3 1 4 5 2</br>1 4 3 5 2</br>4 1 3 5 2</br>3 4 1 5 2</br>4 3 1 5 2</br>1 3 5 4 2</br>3 1 5 4 2</br>1 5 3 4 2</br>5 1 3 4 2</br>3 5 1 4 2</br>5 3 1 4 2</br>1 4 5 3 2</br>4 1 5 3 2</br>1 5 4 3 2</br>5 1 4 3 2</br>4 5 1 3 2</br>5 4 1 3 2</br>3 4 5 1 2</br>4 3 5 1 2</br>3 5 4 1 2</br>5 3 4 1 2</br>4 5 3 1 2</br>5 4 3 1 2</br>2 3 4 5 1</br>3 2 4 5 1</br>2 4 3 5 1</br>4 2 3 5 1</br>3 4 2 5 1</br>4 3 2 5 1</br>2 3 5 4 1</br>3 2 5 4 1</br>2 5 3 4 1</br>5 2 3 4 1</br>3 5 2 4 1</br>5 3 2 4 1</br>2 4 5 3 1</br>4 2 5 3 1</br>2 5 4 3 1</br>5 2 4 3 1</br>4 5 2 3 1</br>5 4 2 3 1</br>3 4 5 2 1</br>4 3 5 2 1</br>3 5 4 2 1</br>5 3 4 2 1</br>4 5 3 2 1</br>5 4 3 2 1</br>array(1) { [0]=> string(0) "" }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/OCL60 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/OCL60 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/OCL60 on line 3
Process exited with code 255.