separate with commas

前端 未结 7 1910
南方客
南方客 2021-01-29 13:45

hey there I have this,

$following_user_id .= $row[\'following_user_id\'];

and I get

44443344330

then I use th

相关标签:
7条回答
  • 2021-01-29 14:24

    Try using arrays, example

    <?php
    $arr = array();
    $arr[] = 'foo';
    $arr[] = 'bar';
    echo implode(',', $arr);
    
    0 讨论(0)
  • 2021-01-29 14:32

    Check implode: http://php.net/manual/en/function.implode.php

    Code example: I'm assuming your using some sort of loop?

    $arrUsers = new array();
    
    ... your loop code here ...
    array_push($arrUsers, $row['following_user_id']);
    ... end loop code .. 
    $following_user_id = impload(",", $arrUsers); 
    
    0 讨论(0)
  • 2021-01-29 14:37

    Collect your data into an array of strings and use the implode function:

    $uids = array();
    while($row = mysql_fetch_assoc($result)){
        array_push($uids, $row['following_user_id']);
    }
    $following_user_id = implode(',', $uids);
    
    0 讨论(0)
  • 2021-01-29 14:39

    You can split the string into an array of characters, then implode the array.

    $array = preg_split('//', $following_user_id, -1, PREG_SPLIT_NO_EMPTY);
    
    echo implode( ',', $array );
    
    0 讨论(0)
  • 2021-01-29 14:40

    This works for me:

    <?php
    $following_user_id.= $row['following_user_id'];
    $following_user_id=preg_replace('/(?<=\d)(?=(\d)+(?!\d))/',',',$following_user_id);
    echo $following_user_id."<br>";
    ?>
    
    0 讨论(0)
  • 2021-01-29 14:44
    $following_user_ids = array();
    
    //loop this:
    $following_user_ids[] = $row['following_user_id'];
    
    $user_ids_string = implode(',',$following_user_ids);
    
    0 讨论(0)
提交回复
热议问题