try something like
$currencies = [] // Create an empty array
foreach($stocks->currency as $currency)
{
$d1 = $currency->cost;
$d2 = $currency->currency->name;
$currencies[] = ' ' . $d1 . ' ' . $d2; // Add a new value to your array
}
echo implode("or", $currencies); // implode the full array and separate the values with "or"
CLICK HERE to find out more related problems solutions.