Skip to content
Advertisement

group result array in PHP

im using array for open a file, if value match in array key, then will open file that related with value. when i try, it will open file as much as data in database.

JavaScript

lets say i have 6 data in database, like :

JavaScript

If data already found in array then just open once file for each key. how to achieve this ? i try using if but data for grade6 open four times. enter image description here

i don’t know how to get deal with this, i search for groupping data with foreach but i don’t know to open a file with foreach. any answer is appreciated.

Advertisement

Answer

Create another array to hold the values you’ve already used, and you can also simplify your code a lot using a loop.

JavaScript

This solution means you no longer have to add an IF block for each grade.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement