How to combine the keys and values of an array in PHP

前端 未结 4 1675
北海茫月
北海茫月 2021-01-17 22:25

Say I have an array of key/value pairs in PHP:

array( \'foo\' => \'bar\', \'baz\' => \'qux\' );

What\'s the simplest way to transform

4条回答
  •  一向
    一向 (楼主)
    2021-01-17 22:40

    chaos' answer is nice and straightfoward. For a more general sense though, you might have missed the array_map() function which is what you alluded to with your map { "$_=$hash{$_}" } keys %hash example.

提交回复
热议问题