I need to Concatenate variables of an array, to execute a 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 just play 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;