replace array keys with given respective keys

前端 未结 10 1420
轻奢々
轻奢々 2020-12-29 09:16

I have an array like below

$old = array(
       \'a\' => \'blah\',
       \'b\' => \'key\',
       \'c\' => \'amazing\',
       \'d\' => array(
          


        
10条回答
  •  盖世英雄少女心
    2020-12-29 09:47

    array_combine(
        ['newKey1', 'newKey2', 'newKey3'],
        array_values(['oldKey1' => 1, 'oldKey2' => 2, 'oldKey3' => 3])
    );
    

    This should do the trick as long as you have the same number of values and the same order.

提交回复
热议问题