php - How to insert a new key and value in multidimensional array? -
following output of multidimensional array $csmap_data
array ( [0] => array ( [cs_map_id] => 84 [cs_subject_id] => 1 ) [1] => array ( [cs_map_id] => 85 [cs_subject_id] => 5 ) [flag] => 1 ) initially there no [flag] => 1 key-value in array, added array $csmap_data. want add [flag] => 1 in above 2 array elements, not separate array element. in short wanted following output :
array ( [0] => array ( [cs_map_id] => 84 [cs_subject_id] => 1 [flag] => 1 ) [1] => array ( [cs_map_id] => 85 [cs_subject_id] => 5 [flag] => 1 ) ) the code trying achieve follows, couldn't desired output:
if (!empty($csmap_data)) { foreach($csmap_data $csm) { $chapter_csmap_details = $objclasssubjects->isclasssubjecthaschapters($csm['cs_map_id']); $csmap_data ['flag'] = 1; } } can me out in obtaining desired output depicted? in advance.
<? foreach($csmap_data $key => $csm) { $csmap_data[$key]['flag'] = 1; } that should trick.
Comments
Post a Comment