Multidimensional Array PHP Implode

前端 未结 5 752
梦如初夏
梦如初夏 2020-12-02 17:48

In terms of my data structure, I have an array of communications, with each communications_id itself containing three pieces of information: id, score, and content.

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 17:59

    this comment based on @jon solution , just add functional code block

    but i have to use loop because array_map does not accept second parameter

    function array_column_implode($data_array = array(),$key = 'id', $delimiter = ',')
    {
      if (function_exists('array_column'))
      {
        return implode($delimiter, array_column($data_array, $key));
      }
      else
      {
        $new_data_array = array();
        foreach ($data_array as $value) {
          if (isset($value[$key]))
          {
            $new_data_array[] = $value[$key];
          }
        }
        return implode($delimiter, $new_data_array);
      }
    }
    

提交回复
热议问题