Php 从关联数组中删除某些键和值

Php 从关联数组中删除某些键和值,php,arrays,Php,Arrays,我有一个如下所示的数组: [['title'= >'my title','time'=>'14:00','date'=>'feb 2'],['title'= >'another','time'=>'14:00','date'=>'feb 2']] [['text'= >'my title'],['text'= >'another title']] 现在我希望从数组中删除所有时间和日期键,并将标题重命名为文本,如下所示: [['title'= &

我有一个如下所示的数组:

[['title'= >'my title','time'=>'14:00','date'=>'feb 2'],['title'= >'another','time'=>'14:00','date'=>'feb 2']]
[['text'= >'my title'],['text'= >'another title']]
现在我希望从数组中删除所有时间日期键,并将标题重命名为文本,如下所示:

[['title'= >'my title','time'=>'14:00','date'=>'feb 2'],['title'= >'another','time'=>'14:00','date'=>'feb 2']]
[['text'= >'my title'],['text'= >'another title']]
我试着用

$tags = array_map(function($tag) {
          return array(
              'text' => $tag['title'],
          );
      }, $tags);

但是我不能让它起作用

这个问题不是拉威尔特有的,但是既然你提到了它:

为方便起见,请使用
collect()
帮助程序及其方法。您将需要查看
映射
,尤其是
转换

如果不使用它,则
unset
将从数组中删除所需的索引

或者,只需创建一个新阵列:

$a = []

foreach($tags as $tag) {
    $a[] = ['text' => $tag['title']];
}
编辑:修复Laravel解决方案:

collect($array)->transform(function($i) { return ['text' => $i['title']]; })->toArray();

你可以改变你的收藏

$mycollection = $myModel->get();

return $mycollection->map(function($row){
    return [
        'text' => $row->title,
    ];
});

或者您可以使用分形:

仍然需要将
标题
索引重命名为
文本
。示例将生成一个项目<代码>$a['text']无法查看数组映射的问题。可能是由于嵌套数组。