I've got this array (print from point [A] in code below):
Array
(
[codigo] =>
[titulo] => Array
(
[0] => musi
[1] => bach
)
[titulo_operador] => OR
[resumo] =>
[autor] =>
[ano_min] =>
[ano_max] =>
[tipo] =>
[categoria] =>
[palavra_chave] =>
[idioma] =>
)
in which I perform these operations... (code is intentionally not-optimized, it could be leaner)
if (!empty($data['titulo'])) {
if (is_array($data['titulo'])) {
$query .= " AND (";
//print_r($data); point [A]
foreach ($data['titulo'] as $value) {
$query_temp .= " ".$data['titulo_operador']." aid.name LIKE '%".$value."%'";
}
//print_r($data); point [B]
$query_temp = trim($query_temp, " ".$data['titulo_operador']." ");
$query .= $query_temp;
unset($query_temp);
$query .= ")";
} elseif (is_string($data['titulo'])) {
$query .= " AND aid.name LIKE '%".$data['titulo']."%'";
}
}
After the foreach, $data['idioma'] is set to 'bach'. This is the print_r in point [B]:
Array
(
[codigo] =>
[titulo] => Array
(
[0] => musi
[1] => bach
)
[titulo_operador] => OR
[resumo] =>
[autor] =>
[ano_min] =>
[ano_max] =>
[tipo] =>
[categoria] =>
[palavra_chave] =>
[idioma] => bach
)
I've removed the $query_temp statement, leaving an empty foreach there and this still happens, so I'm pretty sure there's something in the foreach there... Does foreach in a subarray alter anything in parrent array too?
Edit: I assigned other elements to $data['titulo'] and $data['idioma'] always gets the value of the last element.