Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Jessie25's avatar

passing array value from API

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",
    }
]
0 likes
4 replies
CorvS's avatar
CorvS
Best Answer
Level 27

You could just create a new array matching your desired response:

return ['university' => $accountInfo['university']['student_info']];
1 like
Jessie25's avatar

Thanks @nimrod . I've solve it by changing the

$studsInfo[] = isset($studInfoResp['university']) ? $student['student_info'] : null;

Quick question, how can I display only the studentID object that I want? Thanks :)

CorvS's avatar

What exactly do you mean? Can you give an example?

Jessie25's avatar

Oh basically I wanna display the result let said if only the studentID is match with accountID then only display that value. Yeah, it's okay i've solved the issue above! :) Thanks @nimrod !

1 like

Please or to participate in this conversation.