ホームページ  >  記事  >  バックエンド開発  >  PHP配列の再編成ヘルプ

PHP配列の再編成ヘルプ

WBOY
WBOYオリジナル
2016-06-23 14:39:41858ブラウズ

この投稿は、suifengmin によって最終編集されました: 2013-12-18 13:46:33

現在取得しているものは次のとおりです:
最初の配列:
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        ))


2 番目の配列はループ 1:

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);

基本的には上記の回答をありがとうございます。生成されたものにはまだ配列がありません

実際、最終的に json に変換するために必要な形式は次のようになります。 name":"明明",
"logo":"img/20121102142618 .jpg",
"x":"485",
"y":"260",
"w":"26",
"h ":"34",
"createddate":"2013-12-12",
"diedate":"2013-12-12",
"itme":[{
"0":[{
"name" :"123"、
"ロック":"false"、
"時間":"2013-12-12 12:10:40"、
"ギフト":"img/ae77500803b347fe9986d838b7a5fff3.png"、
"gname": "美しい永遠"、
"gid":"hh0"、
" x":"100"、
"y":"100"、
"w":"100"、
"h":"100"、
"有効期間":"3 日間"、
"dtime":" 2013-12-15 12:10:40"
}]、
"1":[{
"name":"bj"、
"ロック":"true",
"time":"2013-12- 12 12:10:40",
"gift":"img/ae77500803b347fe9986d838b7a5fff3.png",
"gname":"幸福と健康",
" gid":"hh1"、
"x":"200"、
"y":"200"、
"w":"150"、
"h":"150"、
"効果的":"3 days",
"dtime":"2013-12-15 12:10 :40"
}],
"2":[{
"name":"Our World",
"lock":"true",
"time":"2013-12-12 12:10:40 ",
"gift":"img/ae77500803b347fe9986d838b7a5fff3.png",
"gname":"Beautiful Forever",
"gid":"hh2",
"x":"300"、
"y":"300"、
"w":"400"、
"h":"400"、
"有効":"3 日間"、
"dtime" :"2013-12-15 12:10:40"
}]

}]

}]

上の人のおかげで、あなたのヒントに従ってすでに書きました

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
前の記事:定期的な質問次の記事:定期的な質問