Skip to content
Advertisement

How do I remove the extra square bracket from JSON having multiple arrays

I am trying to get JSON from an array but I am getting an extra square bracket in the output.

I tried using $episode[0] = $podcast->getPodcastByCategoryId($id); but it only gives the incomplete output means it gives data of the first iteration from the array. And if I remove [] from $episode that also gives the data of first iteration.

JavaScript

I expect to have only one square bracket but I am getting the output with two square brackets.

This is the out I am receiving from the above code:

JavaScript

According to the recommendation from @splash58 and @Vinesh Goyal, I am getting output like this:

JavaScript

but, what about the square brackets of first data?

Advertisement

Answer

You can merge arrays while getting

JavaScript

Or flatten the result array before converting to json

JavaScript

demo

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