samedi 1 août 2020

PHP - Add new object to every array of objects

Consider this array of objects in PHP:

 array:2 [
      0 => array:4 [
        "Row_Id" => 256
        "Start_Date" => "2020-05-16"
        "account_code" => ""
        "caller_number" => "452"
        ]
    
      1 => array:4 [
        "Row_Id" => 257
        "Start_Date" => "2020-05-16"
        "account_code" => ""
        "caller_number" => "42"
        ]

      2 => array:4 [
        "Row_Id" => 258
        "Start_Date" => "2020-05-16"
        "account_code" => ""
        "caller_number" => "428"
        ]
    ]

I want to add "callee_number:100" in every array so my output should look like these:

     array:2 [
          0 => array:5 [
            "Row_Id" => 256
            "Start_Date" => "2020-05-16"
            "account_code" => ""
            "caller_number" => "452"
            "callee_number" => "100"
            ]
        
          1 => array:5 [
            "Row_Id" => 257
            "Start_Date" => "2020-05-16"
            "account_code" => ""
            "caller_number" => "42"
            "callee_number" => "100"

            ]

          2 => array:5 [
            "Row_Id" => 258
            "Start_Date" => "2020-05-16"
            "account_code" => ""
            "caller_number" => "428"
            "callee_number" => "100"
            ]
        ]

I have taken the above input array in $get variable. Now I am calling array_push to append callee_number to every array:

  array_push($get,[
   'callee_number':'100'
    ]);

Also tried using array_merge but callee_number is not getting appended. How can I achieve that ?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3hYzmUK
via IFTTT

Aucun commentaire:

Enregistrer un commentaire