我有以下对象(下面):
object(stdClass)#49 (1) {
["NewOrder"] => object(stdClass)#50 (12) {
["BTN"] => string(10) "XXXXXXXXXXXXXXXxx"
["PreOrderTransactionId"] => string(22) "XXXXXXXX"
["PartnerOrderId"] => string(17) "XXXXXXXXXXX"
["QwestOrderId"] => string(9) "N57395699"
["SalesCode"] => string(7) "XXXXXXXX"
["OrderStatus"] => string(7) "Pending"
["OrderStatusCode"] => string(4) "OPEN"
["OrderStatusSourceSystem"] => string(5) "CPLUS"
["OrderStatusMessage"] => string(0) ""
["OrderStatusDate"] => string(10) "2013-12-09"
["OrderStatusTime"] => string(8) "08:02:30"
["ProductFamily"] => array(3) {
[0] => object(stdClass)#51 (2) {
["ProductFamilyName"] => string(7) "BUNDLE+"
["ProductLines"] => object(stdClass)#52 (3) {
["WTN"] => string(10) "3033689919"
["AppointmentDate"] => string(10) "2013-12-20"
["Products"] => object(stdClass)#53 (5) {
["ProductName"] => string(36) "INTERNET 100+ MBPS & HOME PHONE PLUS"
["Usoc"] => string(5) "BBBVC"
["Quantity"] => string(1) "1"
["Action"] => string(1) "I"
["Status"] => string(4) "OPEN"
}
}
}
}
}
}
如何在[“NewOrder”]对象之后添加索引[0],如下所示:
object(stdClass)#49 (1) {
["NewOrder"] => array(1) {
[0] => object(stdClass)#50 (12) {
我需要这样做的原因是因为有时它只有一个Order它会有倍数。如果只有一个它会在每个循环中失败。
答案 0 :(得分:0)
if (!is_array($this->view->Orders->NewOrder)) {
$this->view->Orders->NewOrder = array($this->view->Orders->NewOrder);
Zend_Debug::dump($this->view->Orders->NewOrder);
}