二组数据分割成字符串以“,”隔开

WBOY
Release: 2016-06-23 14:21:37
Original
858 people have browsed it

php 数组 字符

Array
(
    [0] => Array
        (
            [mobile] => 13814002394
        )

    [1] => Array
        (
            [mobile] => 13814002395
        )

    [2] => Array
        (
            [mobile] => 13814002396
        )

    [3] => Array
        (
            [mobile] => 13814002397
        )

    [4] => Array
        (
            [mobile] => 13814002398
        )

    [5] => Array
        (
            [mobile] => 13814002399
        )

    [6] => Array
        (
            [mobile] => 13814002400
        )


这是得出的二组数组,我想分割成字符串 $mobile=13814002399,13814002400,13814002398;

这样只的形式

回复讨论(解决方案)

$mobile = join(',', array_map(function($v) { return current($v); }, $arr);

如果PHP版本在5.5还可用array_column()

还有没有答案!!!!!!!!!

$mobile=implode(',',array_map(function($arr){return implode(',',$arr);},$arr));
Copy after login

$array=array(	'0'=>array('mobile'=>'13814002394'),	'1'=>array('mobile'=>'13814002395'),       	'2'=>array('mobile'=>'13814002396'),	'3'=>array('mobile'=>'13814002397'),	'4'=>array('mobile'=>'13814002398'),	'5'=>array('mobile'=>'13814002399'),	'6'=>array('mobile'=>'13814002400'));foreach($array as $key=>$value){	$mobile.=$dot.$value['mobile'];	$dot=",";}return $mobile;
Copy after login

$array=array(	'0'=>array('mobile'=>'13814002394'),	'1'=>array('mobile'=>'13814002395'),       	'2'=>array('mobile'=>'13814002396'),	'3'=>array('mobile'=>'13814002397'),	'4'=>array('mobile'=>'13814002398'),	'5'=>array('mobile'=>'13814002399'),	'6'=>array('mobile'=>'13814002400'));foreach($array as $key=>$value){	$newarray[$key]=$value['mobile'];}return join(",",$newarray);
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template