2
I need to concatenate variables from an array, to run an SQL, this array can have differentiated values. If the array is greater than 1, then it must have $variable + $variavel02. If the array is equal to 1. Then play only the variable.
$array_filial = array($f1, $f2, $f3, $f4);
$filiais = '';
foreach ($array_filial as $key => $f) {
if ($f > 1) {
$filiais .= "" . $f . "+ ";
}
else {
$filiais .= "" . $f . "";
}
}
$in_filial = substr($filiais, -0, -2);
If array > 1
$in_filial = $f1 + $f2;
If array = 1
$in_filial = $f1;
SQL
SELECT(CASE WHEN departamento = 1 AND tipo = 1 THEN (" . $in_filial . ") ELSE 0 END) as total from tabela;
tries to use the implode function
– 13dev
that your code has error? which??
– rLinhares
You want to add all array values, correct?
– Dudaskank