2016-03-02 95 views
-1
Jcart Object(
    [config] => Array 
     (
      [jcartPath] => jcart/ 
      [checkoutPath] => checkout.php 
      [item] => Array 
       (
        [id] => my-item-id 
        [name] => my-item-name 
        [price] => my-item-price 
        [qty] => my-item-qty 
        [url] => my-item-url 
        [add] => my-add-button 
       ) 

      [paypal] => Array 
       (
        [id] => [email protected] 
        [https] => 1 
        [sandbox] => 
        [returnUrl] => 
        [notifyUrl] => 
       ) 

      [currencyCode] => USD 
      [csrfToken] => 
      [text] => Array 
       (
        [cartTitle] => Shopping Cart 
        [singleItem] => Item 
        [multipleItems] => Items 
        [subtotal] => Subtotal 
        [update] => update 
        [checkout] => checkout 
        [checkoutPaypal] => Checkout with PayPal 
        [removeLink] => remove 
        [emptyButton] => empty 
        [emptyMessage] => Your cart is empty! 
        [itemAdded] => Item added! 
        [priceError] => Invalid price format! 
        [quantityError] => Item quantities must be whole numbers! 
        [checkoutError] => Your order could not be processed! 
       ) 

      [button] => Array 
       (
        [checkout] => 
        [paypal] => 
        [update] => 
        [empty] => 
       ) 

      [tooltip] => 1 
      [decimalQtys] => 
      [decimalPlaces] => 1 
      [priceFormat] => Array 
       (
        [decimals] => 2 
        [dec_point] => . 
        [thousands_sep] => , 
       ) 

     ) 

    [items] => Array 
     (
      [0] => 3 
      [1] => poslaju 
     ) 

    [names] => Array 
     (
      [3] => Hockey Stick 
      [poslaju] => Pos Laju 
     ) 

    [prices] => Array 
     (
      [3] => 33.25 
      [poslaju] => 6.00 
     ) 

    [qtys] => Array 
     (
      [3] => 1 
      [poslaju] => 3 
     ) 

    [urls] => Array 
     (
      [3] => http://bing.com 
      [poslaju] => 
     ) 

    [subtotal] => 51.25 
    [itemCount] => 4 
) 

我使用print_r($jcart)得到上面的結果。 我只想打印出[qtys]數組。我嘗試print_r($qtys);但它不起作用。如何打印_r選定的數組?

回答

1

你必須引用數組元素。所以你總是需要指向$jcart,然後從那裏引用。正如謝爾蓋指出,你有一個對象有

Jcart對象

所以你必須引用該對象的元素,而不是一個數組

print_r($jcart->qtys); 
+0

好像'$ jcart'是'Jcart'的實例,因此可能應參考'$ jcart-> qtys'? –

+0

@SergeyChizhik啊,就這樣。第一次閱讀時我錯過了。 – Machavity

+0

非常感謝。它的工作 –

1

使用用於選擇您需要的特定元素的參考鍵。

echo '<pre>'; print_r($jcart->qtys); 

<pre>標記剛添加到瀏覽陣列中的一個更好的格式

+1

你必須添加'true'到'print_r'來連接它,就像這樣 – Machavity

+0

編輯:)謝謝 – Adersh