首页 > 解决方案 > 如何使用 Arr::only 助手重命名数组的键?

问题描述

Arr::only用来通过键从数组中获取值,但是我需要重命名ShortDesc键以使用蛇案例而不是骆驼案例。这是可能的Arr::only还是我需要使用array_map?

这是我的精彩代码。

$myArray = Arr::only($targetArray, ["title", "shortDesc"]);

标签: arrayslaravelhelper

解决方案


看代码:https ://github.com/illuminate/support/blob/master/Arr.php#L367

不,仅使用 Arr::only 函数是不可能实现您需要的。你还需要一些。


推荐阅读