I am passing a shell script array to php file as below.
php file.php ${variable[@]}
The file.php is used to find all the permutations of the given shell script array.
<?php
function pc_array_power_set($array) {
// initialize by adding the empty set
$results = array(array( ));
foreach ($array as $element)
foreach ($results as $combination)
array_push($results, array_merge(array($element), $combination));
return $results;
}
$set = $argv;
$power_set = pc_array_power_set($set);
foreach (pc_array_power_set($set) as $combination) {
if (2 == count($combination)) {
print join("\t", $combination) . "
";
}
}
?>
However, since I use argv as the command line argument for the php file, my output is considering the file name also as an element of the array.
Output:
echo ${variable[@]}
php checking
php file.php ${variable[@]}
The output is coming as,
php done.php
checking done.php
checking php
As we can see, I get the file name also in the output while I just expect the output as,
checking php