I have an array that looks like this
Array
(
[1] => Array
(
[name] => Zeze
[city] => Denver,
[state] => Colorado,
[country] => United States
[user_id] => 1
[cars] => Array
(
[140] => Array
(
[cars_name] => BMW
)
[162] => Array
(
[cars_name] => Mazda
)
)
)
[8] => Array
(
[name] => Lex
[city] => Schwelm,
[state] => North Rhine-Westphalia,
[country] => Germany
[user_id] => 5
[cars] => Array
(
[140] => Array
(
[cars_name] => Mercedes
)
[162] => Array
(
[cars_name] => Audi
)
)
)
)
I need to extract the value from user_id
and put it in a comma separated string.
For the above array, I would like to get:
1,5
I'm a bit confused how to loop this array with foreach
and then how would I create the string? Or is there a better way?