码迷,mamicode.com
首页 > 其他好文 > 详细

arrhelper::map

时间:2016-05-20 17:13:11      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:

$array = [
[‘id‘ => ‘123‘, ‘name‘ => ‘aaa‘, ‘class‘ => ‘x‘],
[‘id‘ => ‘124‘, ‘name‘ => ‘bbb‘, ‘class‘ => ‘x‘],
[‘id‘ => ‘345‘, ‘name‘ => ‘ccc‘, ‘class‘ => ‘y‘],
];

$result = ArrayHelper::map($array, ‘id‘, ‘name‘);
// the result is:
// [
// ‘123‘ => ‘aaa‘,
// ‘124‘ => ‘bbb‘,
// ‘345‘ => ‘ccc‘,
// ]

$result = ArrayHelper::map($array, ‘id‘, ‘name‘, ‘class‘);
// the result is:
// [
// ‘x‘ => [
// ‘123‘ => ‘aaa‘,
// ‘124‘ => ‘bbb‘,
// ],
// ‘y‘ => [
// ‘345‘ => ‘ccc‘,
// ],
// ]

arrhelper::map

标签:

原文地址:http://www.cnblogs.com/yangyuqiu/p/5512615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!