PHP implode without return

Asked

Viewed 42 times

0

//would like to make an implode that returns the numbers in the following order 1,2,3

class Users extends DB{
 //extende a classe de conexao com a database
static function getIds($user_id){

    $select = self::getConn()->prepare('SELECT id FROM `users`');
    $select->execute(array($user_id));

    $d['data'] = $select->fetchAll(PDO::FETCH_ASSOC);
    return $d;
    }
}

//classe de ids dos usuarios "Users"

$user_id = 1;   
$uid = Users::getIds($user_id);

foreach($uid['data'] as $k){
    $arr_ids = array('id' => $k);

    var_dump($arr_ids);
//tentei usar o implode(',', $arr_ids['id']); e não retornou 1,2,3 
/*ira imprimir:
array (size=1)
0 => 
 array (size=1)
   'id' => string '1' (length=1)
 array (size=1)
0 => 
array (size=1)
   'id' => string '2' (length=1)
array (size=1)
0 => 
array (size=1)
  'id' => string '3' (length=1)
*/
}

1 answer

1

To get this result, the array in question must be in the following format:

foreach($uid['data'] as $k){
   $arr_ids[] = $k;
}

This must be outside the FOREACH

Browser other questions tagged

You are not signed in. Login or sign up in order to post.