Merge array items into string

后端 未结 10 1905
遇见更好的自我
遇见更好的自我 2020-11-30 12:33

How do I merge all the array items into a single string?

10条回答
  •  失恋的感觉
    2020-11-30 13:26

    For Multi Array such as:

     $multi_arrays = array(
                0 => array('model' => 'Product 1'),
                1 => array('model' => 'Product 2'),
                2 => array('model' => 'Product 3'),
                3 => array('model' => 'Product 4'));
    
     $pattern = array('/\[/', '/\]/', '/{"model":/', '/}/', '/\"/');
    
     $str_models = preg_replace($pattern, '', json_encode( $multi_arrays));
    

    The result will be:

    Product 1, Product 2, Product 3, Product 4

    You can change pattern for get any result you want!

提交回复
热议问题