如何获得对象像值:项目:私有从PHP数组


How to get object like value:item:private from PHP Array

数组是这样的:

} ["items":"Jcart":private]=> array(3) {[0] =>字符串(1)"3"[1] =>字符串(1)"2"[2] =>
字符串(7)"abc - 123 "}

如何在php变量中获得"项目"值?

///////

完整对象为:

object(Jcart)#1 (8) {
  ["config"]=>
  array(12) {
    ["jcartPath"]=>
    string(6) "jcart/"
    ["checkoutPath"]=>
    string(12) "checkout.php"
    ["item"]=>
    array(6) {
      ["id"]=>
      string(10) "my-item-id"
      ["name"]=>
      string(12) "my-item-name"
      ["price"]=>
      string(13) "my-item-price"
      ["qty"]=>
      string(11) "my-item-qty"
      ["url"]=>
      string(11) "my-item-url"
      ["add"]=>
      string(13) "my-add-button"
    }
    ["paypal"]=>
    array(5) {
      ["id"]=>
      string(38) "seller_1282188508_biz@conceptlogic.com"
      ["https"]=>
      bool(true)
      ["sandbox"]=>
      bool(false)
      ["returnUrl"]=>
      string(0) ""
      ["notifyUrl"]=>
      string(0) ""
    }
    ["currencyCode"]=>
    string(3) "USD"
    ["csrfToken"]=>
    bool(false)
    ["text"]=>
    array(14) {
      ["cartTitle"]=>
      string(13) "Shopping Cart"
      ["singleItem"]=>
      string(4) "Item"
      ["multipleItems"]=>
      string(5) "Items"
      ["subtotal"]=>
      string(8) "Subtotal"
      ["update"]=>
      string(6) "update"
      ["checkout"]=>
      string(8) "checkout"
      ["checkoutPaypal"]=>
      string(20) "Checkout with PayPal"
      ["removeLink"]=>
      string(6) "remove"
      ["emptyButton"]=>
      string(5) "empty"
      ["emptyMessage"]=>
      string(19) "Your cart is empty!"
      ["itemAdded"]=>
      string(11) "Item added!"
      ["priceError"]=>
      string(21) "Invalid price format!"
      ["quantityError"]=>
      string(38) "Item quantities must be whole numbers!"
      ["checkoutError"]=>
      string(34) "Your order could not be processed!"
    }
    ["button"]=>
    array(4) {
      ["checkout"]=>
      string(0) ""
      ["paypal"]=>
      string(0) ""
      ["update"]=>
      string(0) ""
      ["empty"]=>
      string(0) ""
    }
    ["tooltip"]=>
    bool(true)
    ["decimalQtys"]=>
    bool(false)
    ["decimalPlaces"]=>
    int(1)
    ["priceFormat"]=>
    array(3) {
      ["decimals"]=>
      int(2)
      ["dec_point"]=>
      string(1) "."
      ["thousands_sep"]=>
      string(1) ","
    }
  }
  ["items":"Jcart":private]=>
  array(2) {
    [0]=>
    string(1) "3"
    [1]=>
    string(1) "2"
  }
  ["names":"Jcart":private]=>
  array(2) {
    [3]=>
    string(12) "Hockey Stick"
    [2]=>
    string(13) "Baseball Mitt"
  }
  ["prices":"Jcart":private]=>
  array(2) {
    [3]=>
    string(5) "33.25"
    [2]=>
    string(5) "19.50"
  }
  ["qtys":"Jcart":private]=>
  array(2) {
    [3]=>
    string(1) "1"
    [2]=>
    string(2) "20"
  }
  ["urls":"Jcart":private]=>
  array(2) {
    [3]=>
    string(15) "http://bing.com"
    [2]=>
    string(16) "http://yahoo.com"
  }
  ["subtotal":"Jcart":private]=>
  float(423.25)
  ["itemCount":"Jcart":private]=>
  int(21)
}

我只需要["items":"Jcart":private]中的值

我假设您是通过将对象强制转换为数组来实现这一点的。如果是这样的话,你就不应该这么做!属性是私有的,因为你不应该直接访问它,因为它不是公共API。对象应该有一个你应该调用的公共方法,那是公共API。比如$foo->getItems()之类的。阅读文档和/或源代码