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
Post a Comment