Joining arrays where they have a certain field equal

1

How do I join multiple arrays in an array when they have the same fields?

Ihavethisfollowingarraybeingreturned,Iwouldliketogroupthemintoasinglearraywheretheyhavethesamevalueforthequery_id,forexample:inthefirst3arraythathasthequery_id=1,theygetintoanarrayonly,getting,array=[[array1],[array2],[array3]]

Q:Allofthesearraysareinsideanotheronethatiscontainedinthevariable$return

SQL is this: SELECT * FROM respostas INNER JOIN perguntas ON respostas.id_pergunta = perguntas.id_pergunta WHERE perguntas.id_questionario = $id_questionario

    
asked by anonymous 19.11.2017 / 14:03

1 answer

0

If you put example :

while($result = $acesso->result->fetch(PDO::FETCH_ASSOC))
{    
    $retorno[$result['id_pergunta']][] = $result;
}

will group by the key id_pergunta , this happens because the key is the same for that particular item of array , and the grouping happens naturally.

Reference: Arrays

    
19.11.2017 / 14:19