How to use array values as keys without loops?

前端 未结 6 1653
暗喜
暗喜 2020-12-09 16:12

Looping is time consuming, we all know that. That\'s exactly something I\'m trying to avoid, even though it\'s on a small scale. Every bit helps. Well, if it\'s unset of co

6条回答
  •  佛祖请我去吃肉
    2020-12-09 16:43

    This is the fastest and simplest code here so far ...

    $result = [];
    foreach ($input as $subarray) {
        $result[$subarray["id"]] = $subarray["name"];
    }
    

提交回复
热议问题