php - How to make a string from one kind of array items? -


i have array this:

$results = $stmt->fetchall(pdo::fetch_assoc);  /* array (     [0] => array         (             [id] => 191             [type] => 3             [table_code] => 15         )      [1] => array         (             [id] => 192             [type] => 3             [table_code] => 15         )      [2] => array         (             [id] => 194             [type] => 3             [table_code] => 15         ) ) */ 

and i'm trying make string of ids comma separator. this:

echo $expectedoutput; // 193, 192, 194 

how can that?


here i've tried far:

foreach($results $item) {     $expectedoutput = $item['id']; } 

but there , in end of string.

you can using implode , array_column.

array column makes array id of array, , after implode makes string array delimiter. want use ,.

echo implode(", ", array_column($results, "id")); //193, 192, 194 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -