$arrays = array (
'child1_167'=>'1st',
'child1_167'=>'2nd',
'child1_165'=>'2nd',
'child2_165'=>'1st',
'child3_164'=>'2nd',
'child1_164'=>''
);
$classes = array();
foreach ($arrays as $key=>$value) {
if($value != '') {
$exp= explode('_', $key);
$classes[$exp[0]] = $exp[1];
}
}
print_r($classes);
currently it is returning like this:
Array ( [child1] => 165 [child2] => 165 [child3] => 164 )
but i want it to return all the keys and value if value is not blank.
I am actually getting the data from form. and my actual code is foreach ($_post as $key=>$value )
<td>
<select name="child1_<?php echo child_id(); ?>">
<option></option>
<option>1st</option>
<option>2nd</option>
</select>
</td>
<td>
<select name="child2_<?php echo child_id(); ?>">
<option></option>
<option>1st</option>
<option>2nd</option>
</select>
</td>
<td>
<select name="child3_<?php echo child_id(); ?>">
<option></option>
<option>1st</option>
<option>2nd</option>
</select>
</td>
and here is the form post data.
Array ( [child1_167] => 1st [child2_167] => 2nd [child3_167] => [child1_165] => [child2_165] => 1st [child3_165] => 2nd [child1_164] => 2nd [child2_164] => [child3_164] => 1st ) Array ( [167] => 2nd [165] => 2nd [164] => 1st )