我有这个数组,需要小写值并快速添加下划线,因为它可能包含数千个结果。我正在使用 cakephp 3.0 beta 顺便说一句。
到目前为止我所拥有的:
$a = [
(int) 0 => 'Dasdf',
(int) 1 => 'FasDfgh',
(int) 2 => 'CdfDhy',
(int) 3 => 'WrdTghte',
(int) 4 => 'StdFgh',
]
我意识到我可能会走得很远,但这些是我正在考虑使用的功能。我也意识到我的使用可能会有所不同。
$res = Hash::map($a, '{n}', array($this, 'noop'));
$underscore = Inflector::underscore('{Foo}');
$res = Hash::extract($a['{n}'] , Inflector::humanize($underscore) );
这是我需要的结果: $a = [ (int) 0 => 'dasdf', (int) 1 => 'fas_dfgh', (int) 2 => 'cdf_dhy', (int) 3 => 'wrd_tghte' , (int) 4 => 'std_fgh', ]