PHP Splitting an Array into two arrays - keys array and values array

后端 未结 6 1443
夕颜
夕颜 2020-12-14 08:52

Is there an easy way to split an array into two arrays, one consisting of all the keys and the other consisting of all the values? This would be a reverse to the action of

6条回答
  •  感动是毒
    2020-12-14 09:54

    There are two functions actually:

    $keys = array_keys($array);
    $values = array_values($array);
    

    You can also do the exact opposite:

    $array = array_combine($keys, $values);
    

提交回复
热议问题