Suppose I have an array of data like this:
array:2 [
0 => array:2 [
"id" => 7539
"os" => "Android"
]
1 => array:2 [
"id" => 7540
"os" => "iOS"
]
]
I want to grab the id
values only and place them in a variable that's comma separated (i.e $var = "7539,7540";
) using a foreach()
loop but for some reason - my code below outputs just the first value in an array (not an individual value).
How can I fix this so that both values are comma separated in a separate variable?
$var = "";
foreach($dataSet as $data) {
$var = explode(",", $data['id']);
}
dd($var);
Output:
array:1 [
0 => "7539"
]