this might help future poeple even tho its a old tread i had issues getting a array put into a json array at a specific location using push so after some horsing around i came up with: using array_pad(array1,size,array2)
"{MetaData":[ { } ], "pgstyle":{ }, "fonts":{ },
"models":{ }, "Page":[
{
"Type":"Text",
},
{
"Type":"3Dmodel",
"id":"3",
"name":"3D gallery",
"gallerylist":[
{
"model":"Basic Vert frame",
"Type":"imageGallery",
"name":"vertical",
"gId":3,
"id":303,
"LightIntense":7500,
"LightColor":"#ffffcb",
"offset":{
"x":-70,
"y":0,
"z":0
},
"rotation":{
"x":90,
"y":180,
"z":0
},
"font":"Wittgenstein-Bold.ttf"
},
{
"model":"Basic Horz frame",
"Type":"imageGallery",
"name":"Dark Images",
"gId":1,
"id":301,
"LightIntense":5000,
"LightColor":"#ffffcb",
"font":"Wittgenstein-Bold.ttf",
"offset":{
"x":0,
"y":0,
"z":0
},
"rotation":{
"x":90,
"y":180,
"z":0
}
},
{
"model":"Basic Horz frame",
"Type":"imageGallery",
"name":"Dark Light",
"LightIntense":5000,
"LightColor":"#ffffcb",
"gId":2,
"id":302,
"offset":{
"x":70,
"y":0,
"z":0
},
"rotation":{
"x":90,
"y":180,
"z":0
},
"font":"Wittgenstein-Bold.ttf"
}
]} ] }
//the data i want to insert into my json file
$newData =
array("model"=>"$model","Type"=>"imgGallery","name"=>"$Title","gId" =>
(int)$gId,"id"=> (int)$id ,"LightIntense"=>(int)$LightIntensity,
"LightColor"=>"$LightColor","font"=>"$font","offset"=>array("x"=>(int)
($ox),"y"=>(int)$oy,"z"=>(int)$oz),
"rotation"=>array("x"=>90,"y"=>180,"z"=>0 ));
// getting size
$size = sizeof($JData['Page'][$key]['gallerylist'])+1;
//appending data
$JData['Page'][$key]['gallerylist']=array_pad($JData['Page'][$key]
['gallerylist'],
$size,$newData);
alertGreenRefr(var_dump(json_encode($JData,true)));
$Jfile = json_encode($JData,true);
file_put_contents("PageDatatest.json", $Jfile);
RESULT : "{MetaData":[ { } ], "pgstyle":{ }, "fonts":{ }, "models":{ }, "Page":[
{
"Type":"Text",
},
{
"Type":"3Dmodel",
"id":"3",
"name":"3D gallery",
"gallerylist":[
{
"model":"Basic Vert frame",
"Type":"imageGallery",
"name":"vertical",
"gId":3,
"id":303,
"LightIntense":7500,
"LightColor":"#ffffcb",
"offset":{
"x":-70,
"y":0,
"z":0
},
"rotation":{
"x":90,
"y":180,
"z":0
},
"font":"Wittgenstein-Bold.ttf"
},
{
"model":"Basic Horz frame",
"Type":"imageGallery",
"name":"Dark Images",
"gId":1,
"id":301,
"LightIntense":5000,
"LightColor":"#ffffcb",
"font":"Wittgenstein-Bold.ttf",
"offset":{
"x":0,
"y":0,
"z":0
},
"rotation":{
"x":90,
"y":180,
"z":0
}
},
{
"model":"Basic Horz frame",
"Type":"imageGallery",
"name":"Dark Light",
"LightIntense":5000,
"LightColor":"#ffffcb",
"gId":2,
"id":302,
"offset":{
"x":70,
"y":0,
"z":0
},
"rotation":{
"x":90,
"y":180,
"z":0
},
"font":"Wittgenstein-Bold.ttf"
},
{
"model":"Basic Horz frame",
"Type":"imgGallery",
"name":"asdf ",
"gId":4,
"id":304,
"LightIntense":5000,
"LightColor":"#ffffcb",
"font":"Wittgenstein-Bold.ttf",
"offset":{
"x":140,
"y":0,
"z":0
},
"rotation":{
"x":90,
"y":180,
"z":0
}
}
] } ] }
json_decodeit,array_mergeit with the new array, and thenjson_encodeit again.