PHP create key => value pairs within a foreach

后端 未结 5 977
傲寒
傲寒 2021-02-04 04:58

I want to create a key-value pairs in an array within a foreach. Here is what I have so far:

function createOfferUrlArray($Offer) {
    $offerArray = array();

         


        
5条回答
  •  温柔的废话
    2021-02-04 05:16

    In PHP >= 5.3 it can be done like this:

    $offerArray = array_map(function($value) {
        return $value[4];
    }, $offer);
    

提交回复
热议问题