Implode data from a multi-dimensional array

前端 未结 7 989
梦毁少年i
梦毁少年i 2020-11-22 12:30

I\'m a novice at PHP and I need a quick solution to the following problem but can\'t seem to come up with one:

I have a multi-dimensional array like so



        
7条回答
  •  故里飘歌
    2020-11-22 12:40

    Quite simple:

    $input = array(
      array(
        'tag_name' => 'google'
      ),
      array(
        'tag_name' => 'technology'
      )
    );
    
    echo implode(', ', array_map(function ($entry) {
      return $entry['tag_name'];
    }, $input));
    

    http://3v4l.org/ltBZ0


    and new in php v5.5.0, array_column:

    echo implode(', ', array_column($input, 'tag_name'));
    

提交回复
热议问题