I’m trying to API response in multiple curly braces,
but it’s not coming.
below is my code.
/**
* @return array
*/
public function Newdata()
{
//get Customer Order collection by Customer Id and Email Magento 2
$customerCollection = $this->_customer->getCollection()
->addAttributeToSelect("*")
->load();
$customeid = $customerCollection->getData('customer_id');
try {
//$customerEmailId = "ncode.rushikesh@gmail.com";
$customerID = $customeid;
$customerOrder = $this->orderCollectionFactory->create()->addAttributeToFilter('customer_email', $customerID)->load();
$finalArray = [];
if(!empty($customerOrder->getData())){
foreach ($customerOrder as $item) {
$finalArray[] = $item->getEntityId();
}
//$finalArray['entity_id'] = $customerOrder->getData();
$response = ['success' => 200, 'message' => 'Success', 'data' => $finalArray];
}else{
$response = ['success' => 404, 'message' => "Data Not Found", 'data' => []];
}
}catch (Exception $e) {
$response = ['success' => false, 'message' => $e->getMessage(), 'data' => []];
$this->logger->info($e->getMessage());
}
return [$response];
}
}
OUTPUT
[
{
"success": 200,
"message": "Success",
"data": [
"1",
"2",
"3"
]
}
]
but i need like
[
{
"success": 200,
"message": "Success",
"data": [
{"1"},
{"2"},
{"3"}
]
}
]
how can i do that?? pls help me on this.