laravel – Can i add new items to an array that already has some existing items?

  arrays, laravel, laravel-8, php, variables

$response is an array like below:

       [
        {
            "courseId": 14,
            "tutorName": "admin"
        },]

The below code gives a result like this: "data": 3 .I wanted add a new item called points with the first array. But here, it overwrites the existing array.How can i achieve this?

$dat=array_push($response,array('points'=>"3"));
 return response()->json(['data' => $dat], 200);

Expected output:

       [
        {
            "courseId": 14,
            "tutorName": "admin",
            "points": 3
        },]

Source: Ask PHP

LEAVE A COMMENT