What does this snippet of PHP do? My validations fail because of it

-1

I'm working on a project I've already taken and I'm having trouble displaying data for certain validations. I need to understand what this line does:

foreach ($queries as $id => $query) 
    if (!in_array($id, array('pagina', 'codigo', 'cidade', 'finalidade', 'tipo', 'imovel', 'bairro', 'dormitorios', 'valorMin', 'valorMax')) || empty($query)) 
        unset($queries[$id]);

Can someone "translate"?

    
asked by anonymous 10.03.2014 / 21:31

1 answer

4

Line by line:

foreach ($queries as $id => $query) 

Loop over array $queries . For each item, the key value will be stored in $id , and what is under the key will be stored in $query .

    if (!in_array($id, array('pagina', 'codigo', 'cidade', 'finalidade', 'tipo', 'imovel', 'bairro', 'dormitorios', 'valorMin', 'valorMax')) || empty($query)) 

If the current key is none of those listed, or if the content of $query is empty

        unset($queries[$id]);

Remove the $id key from the $queries array.

    
10.03.2014 / 22:49