I have an array called $brand_terms. I'm accessing two objects in this array. In this case 'name' and 'slug'. I'm then trying to set values of these objects in an associative array called $values. The code is below:
$brand_terms = get_terms("pa_brand");
$values = array(
foreach ($brand_terms as $brand_term){
$brand_term->name => $brand_$term->slug,
}
);
The problem I have is with the separator ,. So the comma at the end of $brand_term->name => $brand_$term->slug,. If the loop is at the last value in the array, the comma is not needed and the the code is broken. Is there a nice way to remove this comma from the last iteration of the foreach loop?
Thanks