2016-03-02 49 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