How to insert a new key value pair in array in php?

后端 未结 4 1088
小蘑菇
小蘑菇 2020-12-30 20:17

I\'ve an array as follows named $test_package_data. For the reference I\'m printing first two elements of it:

Array
(
    [0] => Array
               


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 21:03

    Try this:

    foreach($array as $k => $obj) { 
        $obj->{'newKey'} = "value"; 
    }
    

提交回复
热议问题