You could just create a new array matching your desired response:
return ['university' => $accountInfo['university']['student_info']];
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey Guys, I have a question here. How can I passing the value inside student_info into university? This is how my API response looks right now
"university": [
{
"student_info": {
"studentID": "511000000012029",
"student_firstName": "John",
"student_lastName": "Smith",
"student_contactNumber": "750000000000023",
"student_paymentType": "1"
}
}
]
And this is my function in UniversityController.php
$studInfo = [];
$studInfoResp = $this->student->getStudentInfo($accountReq);
if(isset($studInfoResp['university']) && count($studInfoResp['university']) > 0) {
foreach($accountResp['cms_acctBasicList'] as $account) {
$accountInfoReq = ['cms_acctCode' => $account['cmc_acctCode']];
$accountInfoResp = $this->billing->getAccountInfo($accountInfoReq, false);
$accountInfo = isset($accountInfoResp['cms_accountInfo']) ? $accountInfoResp['cms_accountInfo'] : null;
$accountList[$account['cmc_acctId']] = [];
foreach($studInfoResp['university'] as $key => $student) {
// display all the studentInfo
$studsInfo = isset($studInfoResp['university']) ? $studInfoResp['university'] : null;
if($account['cmc_acctId'] === $student) {
array_push($studsInfo, $key);
}
}
$accountInfo['university'] = $studsInfo;
array_push($accountList[$account['cmc_acctId']], $accountInfo);
}
}
I would like to have my final result in API response be like this:
"university": [
{
"studentID": "511000000012029",
"student_contactNumber": "750000000000023",
"student_paymentType": "1",
}
]
You could just create a new array matching your desired response:
return ['university' => $accountInfo['university']['student_info']];
Please or to participate in this conversation.