0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【PHP】連想配列の配列の書き方

Last updated at Posted at 2020-03-04

jsonで連想配列の配列を送信しようとしたのだけど、どう書けばいいか分からず半日くらい詰まったのでメモ。
[20200307]うろ覚えで書いたら盛大に間違っていたのでコードを修正しました

連想配列の配列.php
$arr = array(
        '表題' => '名簿',
        'リスト' => array([
            '名前' => '佐藤',
            '年齢' => 21,
            '出身' => '兵庫県',
            ],[
            '名前' => '高橋',
            '年齢' => 22,
            '出身' => '京都府',
            ],[
            '名前' => '鈴木',
            '年齢' => 25,
            '出身' => '愛知県',
        ]),
);
echo json_encode($arr, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT );

echoの内容

{
    "表題": "名簿",
    "requestList": [
        {
            "名前": "佐藤",
            "年齢": 21,
            "出身": "兵庫県"
        },
        {
            "名前": "高橋",
            "年齢": 22,
            "出身": "京都府"
        },
        {
            "名前": "鈴木",
            "年齢": 25,
            "出身": "愛知県"
        }
    ]
}

C言語では配列初期化が{}なので[]は違和感が凄いです。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?