php数组重组求助
第一个数组:
Array( [0] => Array ( [themes] => default/skin/index.swf [name] => 测试 [logo] => http://6.com/upload_files/article/2/1_20131217101219_mvnun.jpg [x] => 485 [y] => 260 [w] => 26 [h] => 34 [createdate] => 2013-12-17 [diedate] => 2013-12-02 ))
第二个数组 也就是循环的一个:
Array( [0] => Array ( [name] => admin [lock] => 1 [time] => 1970-01-01 [gift] => img/ae77500803b347fe9986d838b7a5fff3.png [gname] => 测试1 [gid] => 1 [x] => 150 [y] => 150 [w] => 150 [effective] => 3 [dtime] => 1970-01-01 ) [1] => Array ( [name] => admin [lock] => [time] => 1970-01-01 [gift] => img/ae77500803b347fe9986d838b7a5fff3.png [gname] => 测试2 [gid] => 1 [x] => 150 [y] => 150 [w] => 150 [effective] => 3 [dtime] => 1970-01-01 ) )
组合为下面的
Array( [0] => Array ( [themes] => img/101228180517877.swf [name] => 明明 [logo] => img/20121102142618.jpg [x] => 485 [y] => 260 [w] => 26 [h] => 34 [createdate] => 2013-12-12 [diedate] => 2013-12-12 [itme] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [name] => 123 [lock] => false [time] => 2013-12-12 12:10:40 [gift] => img/ae77500803b347fe9986d838b7a5fff3.png [gname] => 美丽永久 [gid] => hh0 [x] => 100 [y] => 100 [w] => 100 [h] => 100 [effective] => 3天 [dtime] => 2013-12-15 12:10:40 ) ) [1] => Array ( [0] => Array ( [name] => bj [lock] => true [time] => 2013-12-12 12:10:40 [gift] => img/ae77500803b347fe9986d838b7a5fff3.png [gname] => 幸福健康 [gid] => hh1 [x] => 200 [y] => 200 [w] => 150 [h] => 150 [effective] => 3天 [dtime] => 2013-12-15 12:10:40 ) ) [2] => Array ( [0] => Array ( [name] => 我们的世界 [lock] => true [time] => 2013-12-12 12:10:40 [gift] => img/ae77500803b347fe9986d838b7a5fff3.png [gname] => 美丽永久 [gid] => hh2 [x] => 300 [y] => 300 [w] => 400 [h] => 400 [effective] => 3天 [dtime] => 2013-12-15 12:10:40 ) ) ) ) ))
回复讨论(解决方案)
可以直接赋值,不知道符不符合你的应用
$a = array( array( 'themes' => 'default/skin/index.swf', 'name' => '测试', 'logo' => 'http://6.com/upload_files/article/2/1_20131217101219_mvnun.jpg', 'x' => 485, 'y' => 260, 'w' => 26, 'h' => 34, 'createdate' => 2013-12-17, 'diedate' => 2013-12-02 ),);$b = array( array ( 'name' => 'admin', 'lock' => 1, 'time' => 1970-01-01, 'gift' => 'img/ae77500803b347fe9986d838b7a5fff3.png', 'gname' => '测试1', 'gid' => 1, 'x' => 150, 'y' => 150, 'w' => 150, 'effective' => 3, 'dtime' => 1970-01-01 ), array ( 'name' => 'admin', 'lock' => '', 'time' => 1970-01-01, 'gift' => 'img/ae77500803b347fe9986d838b7a5fff3.png', 'gname' => '测试2', 'gid' => 1, 'x' => 150, 'y' => 150, 'w' => 150, 'effective' => 3, 'dtime' => 1970-01-01 ) );$a[0]['itme']= $b;print_r($a);
感谢楼上的回答 基本差不多 生成出来的还是少了一个 array
其实最后是要转为 json 的 最后需要的格式必须是:
[{
"themes":"img/101228180517877.swf",
"name":"明明",
"logo":"img/20121102142618.jpg",
"x":"485",
"y":"260",
"w":"26",
"h":"34",
"createdate":"2013-12-12",
"diedate":"2013-12-12",
"itme":[{
"0":[{
"name":"123",
"lock":"false",
"time":"2013-12-12 12:10:40",
"gift":"img/ae77500803b347fe9986d838b7a5fff3.png",
"gname":"美丽永久",
"gid":"hh0",
"x":"100",
"y":"100",
"w":"100",
"h":"100",
"effective":"3天",
"dtime":"2013-12-15 12:10:40"
}],
"1":[{
"name":"bj",
"lock":"true",
"time":"2013-12-12 12:10:40",
"gift":"img/ae77500803b347fe9986d838b7a5fff3.png",
"gname":"幸福健康",
"gid":"hh1",
"x":"200",
"y":"200",
"w":"150",
"h":"150",
"effective":"3天",
"dtime":"2013-12-15 12:10:40"
}],
"2":[{
"name":"我们的世界",
"lock":"true",
"time":"2013-12-12 12:10:40",
"gift":"img/ae77500803b347fe9986d838b7a5fff3.png",
"gname":"美丽永久",
"gid":"hh2",
"x":"300",
"y":"300",
"w":"400",
"h":"400",
"effective":"3天",
"dtime":"2013-12-15 12:10:40"
}]
}]
}]
感谢楼上的 我已经根据你的提示写好了