Skip to content

Instantly share code, notes, and snippets.

@jun-ya
Created September 25, 2013 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jun-ya/6702350 to your computer and use it in GitHub Desktop.
Save jun-ya/6702350 to your computer and use it in GitHub Desktop.
php5.4から連想配列表現が簡単になったので、array()だらけの配列定義がちょっとだけ見やすくなった。
<?
/**
* 古い連想配列表現方法を使った多重配列定義例
*
*/
$array_old = array(
array('index' => 1,
array('hoge' => 'hohoho', 'fuga' => 'fufufu'),
array('updated_at' => time()),
),
array('index' => 20,
array('hoge' => 'gegege', 'fuga' => 'gagaga'),
array('updated_at' => time()),
),
array('index' => 300,
array('hoge' => 'ohohoh', 'fuga' => 'ufufuf'),
array('updated_at' => time()),
),
array('index' => 4000,
array('hoge' => 'egegeg', 'fuga' => 'egegeg'),
array('updated_at' => time()),
),
);
/**
* php5.4から採用された新しい連想配列表現方法を使った多重配列定義例
*
*/
$array_new = [
['index' => 1,
['hoge' => 'hohoho', 'fuga' => 'fufufu'],
['updated_at' => time()],
],
['index' => 20,
['hoge' => 'gegege', 'fuga' => 'gagaga'],
['updated_at' => time()],
],
['index' => 300,
['hoge' => 'ohohoh', 'fuga' => 'ufufuf'],
['updated_at' => time()],
],
['index' => 4000,
['hoge' => 'egegeg', 'fuga' => 'egegeg'],
['updated_at' => time()],
],
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment