How to create an array under an alreay present key in PHP? -
i've following array titled $grid_data follows:
array ( [0] => array ( [question_id] => 50147 [question_parent_id] => 0 [question_subject_id] => 4 [question_topic_id] => 219 [question_directions] => [question_text] => wooden scale of length l , mass m lying on frictionless table. particle of mass m moving velocity v, @ distanced centre shown in fig. 93 strikes scale , adherses it. of follwoing quantity (quantities) (are) conserved system. [question_solution] => [question_file] => [question_description] => [question_difficulty_type] => 2 [question_has_sub_ques] => 0 [question_picked_individually] => no [question_appeared_count] => 0 [question_manual] => 0 [question_has_solution] => 0 [question_site_id] => [question_created_staff_id] => 4e4078987c90dbf4ee477f480ad1b874 [question_added_date] => 1329728799 [question_updated_staff_id] => 1096ab29ecde5cec198bb2ebe730d229 [question_updated_date] => 1340253386 [que_issue_id] => 1 [reported_site_id] => entprm [reported_user_type] => student [reported_user_id] => 395599c5891c1418357e2efa89bc3e27 [que_issue] => question wrong,other [que_issue_comment] => happy question [que_issue_status] => 0 [que_issue_date] => 1394517725 [que_issue_fixed_date] => 0 [question_lock] => 1 [ques_ans] => array ( [0] => array ( [answer_id] => 198739 [answer_question_id] => 50147 [answer_text] => linear momentum [answer_file] => [answer_description] => [answer_is_right] => 0 ) [1] => array ( [answer_id] => 198740 [answer_question_id] => 50147 [answer_text] => angular momentum [answer_file] => [answer_description] => [answer_is_right] => 0 ) [2] => array ( [answer_id] => 198741 [answer_question_id] => 50147 [answer_text] => kinetic energy [answer_file] => [answer_description] => [answer_is_right] => 0 ) [3] => array ( [answer_id] => 198742 [answer_question_id] => 50147 [answer_text] => linear momentum , angular momentum both [answer_file] => [answer_description] => [answer_is_right] => 1 ) ) ) [1] => array ( [question_id] => 21679 [question_parent_id] => 0 [question_subject_id] => 5 [question_topic_id] => 285 [question_directions] => [question_text] => in electrical cable there single wire of radius 9 mm of copper. resistance �math xmlns=�http://www.w3.org/1998/math/mathml���mn�5�/mn��mo��nbsp;�/mo��mi��#937;�/mi��/math�. cable replaced 6 different insulated copper wires, radius of each wire 3mm. total resistance of cable [question_solution] => [question_file] => [question_description] => [question_difficulty_type] => 2 [question_has_sub_ques] => 0 [question_picked_individually] => no [question_appeared_count] => 0 [question_manual] => 0 [question_has_solution] => 0 [question_site_id] => [question_created_staff_id] => fbfee12504bf3c4a038d4c9f142f894e [question_added_date] => 1326440661 [question_updated_staff_id] => 1096ab29ecde5cec198bb2ebe730d229 [question_updated_date] => 1338368619 [que_issue_id] => 2 [reported_site_id] => entprm [reported_user_type] => staff [reported_user_id] => ff8d4a5ea6bf11dce105aa2fa7b959b8 [que_issue] => question incomplete/wrong,directions missing [que_issue_comment] => [que_issue_status] => 0 [que_issue_date] => 1395655234 [que_issue_fixed_date] => 0 [question_lock] => 1 [ques_ans] => array ( [0] => array ( [answer_id] => 573122 [answer_question_id] => 21679 [answer_text] => «math xmlns=¨http://www.w3.org/1998/math/mathml¨»«mn»7«/mn»«mo».«/mo»«mn»5«/mn»«mo»§nbsp;«/mo»«mi»§#937;«/mi»«/math» [answer_file] => [answer_description] => [answer_is_right] => 1 ) [1] => array ( [answer_id] => 573123 [answer_question_id] => 21679 [answer_text] => «math xmlns=¨http://www.w3.org/1998/math/mathml¨»«mn»45«/mn»«mo»§nbsp;«/mo»«mi»§#937;«/mi»«/math» [answer_file] => [answer_description] => [answer_is_right] => 0 ) [2] => array ( [answer_id] => 573124 [answer_question_id] => 21679 [answer_text] => «math xmlns=¨http://www.w3.org/1998/math/mathml¨»«mn»90«/mn»«mo»§nbsp;«/mo»«mi»§#937;«/mi»«/math» [answer_file] => [answer_description] => [answer_is_right] => 0 ) [3] => array ( [answer_id] => 573125 [answer_question_id] => 21679 [answer_text] => «math xmlns=¨http://www.w3.org/1998/math/mathml¨»«mn»270«/mn»«mo»§nbsp;«/mo»«mi»§#937;«/mi»«/math» [answer_file] => [answer_description] => [answer_is_right] => 0 ) ) ) )
now ignore rest of array , concentrate on 2 key elements above array follows:
[que_issue] => question wrong,other //from first array [que_issue] => question incomplete/wrong,directions missing //from second array
actually want convert comma separated strin array under key [que_issue] every array element present in array. want output in following manner in above array($grid_data
):
/*oputput first array element array `$grid_data`*/ [que_issue] => array( [0] => question wrong [1] =>other ) /*oputput second array element array `$grid_data`*/ [que_issue] => array( [0] => question incomplete/wrong [1] => directions missing )
now can me in manipulating array $grid_data
in order have above output each array element present in it? in advance.
easy enough foreach
, explode
:
foreach($grid_data &$array) { $array['que_issue'] = explode(',', $array['que_issue']); }
or:
foreach($grid_data $key => $array) { $grid_data[$key]['que_issue'] = explode(',', $array['que_issue']); }
Comments
Post a Comment