PHP 内爆函数错误,不包括内爆字符串

PHP implode function error, does not include implode string

我正在使用 laravel 5.8 并试图让 foreach 内爆

foreach($stocks->currency as $currency)
{
  $d1 = $currency->cost;
  $d2 = $currency->currency->name;
  $currencies = array(' ' . $d1 . ' ' . $d2);
  echo implode("or", $currencies);
}

是我的代码块

然而,这 returns 以下 :

显然这缺少内爆应该添加的“或”

提前致谢!

试试

$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"