This question already has an answer here:
- How to echo or print an array in PHP? 11 answers
I would like to do certain calculation in a function that takes a constant value against different values. To do that I created an array and a variable and also a loop that will take each member of the array and the constant value and pass them to the function that does the calculation. I would like to get an array and then I can do more calculations subsequently.
function subtract($a, $b){
$c=$b-$a;
return $c. ',';
}
$r=3;
$numbers = array(12, 11, 6, 9);
foreach ($numbers as $index=>$value) {
$deductions=array(subtract($r, $value));
//$minimum=min($deductions);
if (is_array($deductions)){
//echo $deductions;
}else{
//echo "not array";
}
}
//$minimum=min($deductions);
//echo $minimum;
echo $deductions;
I get "Array" and not 9,8,3,6 Why is this? Any help is greatly appreciated. echo was partial problem, I get Array ( [0] => 6, ) not 9,8,3,6 as I expected?
</div>