Re: Permutations help in php
Hello
You would like to try this code. If I am not wrong this will work as you are expecting. Try it.
Code:
<?php
$arr1 = array('r', 'b', 'g');
$arr2 = array('c', 'e', 'm');
$arr_perm = get_permutations($arr1, $arr2);
print_r($arr_perm);
function get_permutations($array1, $array2)
{
$result = '';
foreach($array1 as $elem1)
{
foreach($array2 as $elem2)
{
$result[] = $elem1 . ' ' . $elem2;
}
}
return $result;
}
?>
Re: Permutations help in php
Hello
The above example is correct. This can be alternatively done in this way also. Just try to add your knowledge.
Code:
$colors = array('red', 'b', 'g');
$animals = array('c', 'e', 'm');
foreach ($colors as $color) {
foreach ($animals as $animal) {
echo $color . " " . $animal . "<br />";
}
}
Want any more help, then do post back.
Re: Permutations help in php
Hi
Thanks for your help and your code. Both the codes are working correctly. Thanks again for the simple example which are easy to understand.