Skip to content
Advertisement

Merge multiple CodeIgniter result sets into one array

Data queried from the database.

JavaScript

and

JavaScript

Here I create a method called `GetData(), I create a loop from 1-12 based on the months in a year. Next I want to combine data in an array, but how do I combine the data?

Below is my controller model which calls the same model method over and over with different parameters:

JavaScript

I want an output like this:

JavaScript

In 2021, the total is only until the month of 02, while in 2020 the total is until month 12.

If 2021 is only up to month 02 then the next array is total null.

Advertisement

Answer

This, I believe, will assist you in developing the solution. I haven’t included the entire array of $year_2020, but I hope you get the idea –

JavaScript

Output

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