I have this query.
// build query to get their order details
$orderEntity = $em->createQueryBuilder()
->select('oh.orderHeaderId','oh.orderDate', 'oh.orderTotal', 'od.createdDate', 'od.productName', 'od.flashSalePrice', 'od.itemQuantity')
->from('FLOEcommerceBundle:OrderHeader','oh')
->leftJoin('FLOEcommerceBundle:OrderDetail', 'od' ,'WITH', 'oh.orderHeaderId = od.orderHeaderId')
->where('oh.memberId = ?1')
->orderby('oh.orderDate' , 'desc')
->setParameter(1, $memberId)
->getQuery()
->getArrayResult();
The result set dumped is.
array:3 [▼
0 => array:7 [▼
"orderHeaderId" => 25
"orderDate" => DateTime {#3906 ▼
+"date": "2015-07-15 11:27:59.000000"
+"timezone_type": 3
+"timezone": "America/Tegucigalpa"
}
"orderTotal" => "33.9600"
"createdDate" => DateTime {#3904 ▼
+"date": "2015-07-15 11:28:00.000000"
+"timezone_type": 3
+"timezone": "America/Tegucigalpa"
}
"productName" => "Plain Skirt"
"flashSalePrice" => "10.9900"
"itemQuantity" => 1
]
My questions are a) how do return just the date? and/or b) how do I loop through the "orderDate" key to get the "date"? I using a foreach to loop through the arrays to build an output variable. Thank you in advance.
foreach ( $orderEntity as $items ) {
foreach ( $items as $key => $value ) {
if( 'orderHeaderId' == $key) {
$orders .= ' OrderId: ' . $value . $br;
}
}
foreach ( $items as $key => $value ) {
if( 'orderDate' == $key ) {
$orders .= ' OrderDate: ' . $value . $br;
}
}
}