I have previously asked this question
Create Json in PHP using database
which was answered and it worked, however requirement changed a bit and new output that I am trying to get isn't being achieved through this script.
This script give me this output
{
"channelsCategories":
[
{
"name":"Movie",
"contents":
[
{
"name":"Channel 1",
"image":"Thanks.jpg",
},
{
"name":"Channel 2",
"image":"Thanks.jpg",
},
{
"name":"Channel 4",
"image":"amazon-logo...",
},
{
"name":"High",
"image":"Thanks.jpg",
}
]
},
{
"name":"Documentary",
"contents":
[
{
"name":"Channel 7",
"image":"amazon.....",
}
]
}
]
}
new requirement is to add an image field in category array as well as below.
{
"channelsCategories":
[
{
"name":"Movie",
"image": "MoviePoster",
"contents":
[
{
"name":"Channel 1",
"image":"Thanks.jpg",
},
{
"name":"Channel 2",
"image":"Thanks.jpg",
},
{
"name":"Channel 4",
"image":"amazon-logo...",
},
{
"name":"High",
"image":"Thanks.jpg",
}
]
},
{
"name":"Documentary",
"image": "MoviePoster",
"contents":
[
{
"name":"Channel 7",
"image":"amazon.....",
}
]
}
]
}
So far I have achieved this array result, over which I want to loop and get the above output.
array(8) {
["Movieposter"]=> string(7) "Movieposter"
["News"]=> array(2) {
[0]=> array(5) {
["name"]=> string(8) "Dunya tv"
["url"]=> string(4) "http"
["image"]=> string(4) "http"
["type"]=> string(1) "3"
["status"]=> string(6) "Enable"
}
[1]=> array(5) {
["name"]=> string(6) "Geo tv"
["url"]=> string(4) "http"
["image"]=> string(4) "http"
["type"]=> string(1) "3"
["status"]=> string(6) "Enable"
}
}
["Dramaimg"]=> string(8) "Dramaimg"
["Drama"]=> array(2) {
[0]=> array(5) {
["name"]=> string(7) "drama 1"
["url"]=> string(4) "http"
["image"]=> string(4) "http"
["type"]=> string(1) "3"
["status"]=> string(6) "Enable"
}
[1]=> array(5) {
["name"]=> string(7) "drama 2"
["url"]=> string(4) "http"
["image"]=> string(4) "http"
["type"]=> string(1) "4"
["status"]=> string(6) "Enable"
}
}
["entertainmentimg"]=> string(16) "entertainmentimg"
["Entertainment"]=> array(1) {
[0]=> array(5) {
["name"]=> string(8) "indian 1"
["url"]=> string(4) "http"
["image"]=> string(4) "http"
["type"]=> string(1) "3"
["status"]=> string(6) "Enable"
}
}
["Pakistanimg"]=> string(11) "Pakistanimg"
["Pakistan"]=> array(1) {
[0]=> array(5) {
["name"]=> string(8) "pcontent"
["url"]=> string(8) "pcontent"
["image"]=> string(4) "http"
["type"]=> string(1) "7"
["status"]=> string(6) "Enable"
}
}
}
Any help guidance will be appreciated.
'image' => 'MoviePoster'to the array in the secondforeachloop.