I\'ve an array as follows named $test_package_data
. For the reference I\'m printing first two elements of it:
Array
(
[0] => Array
To add:
$arr["key"] = "value";
Then simply return $arr
Can't return directly like this way return $arr["key"] = "value";
foreach($test_package_data as $key=>$data ) {
$category_detail_arr = $test_package_data[$key]['category_detail'];
foreach( $category_detail_arr as $i=>$value ) {
$test_package_data[$key]['category_detail'][$i]['count'] = $some_value;////<----Here
}
}
If you are creating new array then try this :
$arr = ['key' => 'value'];
And if array is already created then try this :
$arr['key'] = 'value';
Try this:
foreach($array as $k => $obj) {
$obj->{'newKey'} = "value";
}