如何使用 echo 将字符串识别为数组

How to recognize string as array with echo

我有一个 woocommerce 的短代码,可以显示客户下的所有订单,它有效。但是,我找到了一段代码,它给了我以下信息:

Notice: Array to string conversion in /home/vwzidcur/public_html/wp-content/themes/astra-child/woocommerce/woo-shortcodes.php on line 67. On line 67 of my file i have echo.

谷歌搜索和阅读官方 php 手册我得出的结论是,问题可以通过 implode 或通过使用 foreach 迭代 $downloads 数组来解决。我试过了但做不到。我对此比较陌生,如有任何帮助,我们将不胜感激。

$customer = wc_get_orders(['customer_id' => get_current_user_id(),]);

foreach ( $customer as $order ) {
foreach ( $order->get_items() as $item_id => $item ) {

$downloads = $order->get_downloadable_items();

  if ($downloads){ 
  wc_get_template(
    'button-downloads-dashboard.php',
     array(
     'downloads'  => $downloads,
     ));
     }

echo '<div class="container_orders_img"> '. $downloads .' </div>';
}}

尝试这样的事情;

// FIRST ALWAYS CHECK IF ITS AN ARRAY
if(is_array($downloads)){
  // START THE LOOP
  foreach($downloads as $product){
    // HERE YOU CHOOSE WHAT TO PRINT OF ALL THE DIFFERENT VARIABLES IN THE ARRAY
    echo '<div class="container_orders_img"><a href="'. $product['download_url'] .'" target="_blank">'. $product['product_name'] .' </a></div>';
  } // END LOOP
} // END IF ARRAY