【发布时间】:2010-12-21 16:08:39
【问题描述】:
在 perl 中,我可以将一个列表分配给哈希中的多个值,如下所示:
# define the hash...
my %hash = (
foo => 1,
bar => 2,
baz => 3,
);
# change foo, bar, and baz to 4, 5, and 6 respectively
@hash{ 'foo', 'bar', 'baz' } = ( 4, 5, 6 );
有没有办法在 php 中做同样的事情?事实上,有没有办法获得一个 assoc 数组的切片?
【问题讨论】:
-
注意:我已经知道 list 并且问题的重点是找到比以下更优雅的解决方案: list ( $array['a'], $array['b'], $array['c'], $array['d'], $array['e'], $array['f'], $array['g'], $array['h'], $array ['i'], $array['j'], $array['k'], $array['l'], $array['m'] ) = some_function();
标签: php associative-array slice