A regex-based solution seems appropriate for this question.
preg_grep () is a function designed to apply a regular expression filter to each value in an array. For this case, a little more settings are required, because instead you need to filter the keys.
Single line :
$output=array_intersect_key($input,array_flip(preg_grep("/^\d+_1$/",array_keys($input))))); /* array ( '5_1' => 23, '6_1' => 3.3, '4_1' => 23.2, )*/
Here is the stepwise manipulation of arrays ...
array_keys($input); // create array with input keys as values /* array ( 0 => 'initial', 1 => 'hour', 2 => 'row_checker_1', 3 => 'project_name_1', 4 => 'project_shortcode_1', 5 => '5_1', 6 => '6_1', 7 => '4_1', 8 => 'remarks_1', 9 => 'task_id', 10 => 'row_checker_2', 11 => 'project_name_2', 12 => 'project_shortcode_2', 13 => '5_2', 14 => '6_2', 15 => '4_2', 16 => 'remarks_2', ) */ preg_grep("/^\d+_1$/",array_keys($input)); // filter the input array using regex pattern /* array ( 5 => '5_1', 6 => '6_1', 7 => '4_1', ) */ array_flip(preg_grep("/^\d+_1$/",array_keys($input))); // flip the filtered array /* array ( '5_1' => 5, '6_1' => 6, '4_1' => 7, )*/ array_intersect_key($input,array_flip(preg_grep("/^\d+_1$/",array_keys($input)))); // filter input by comparing keys against filtered array /* array ( '5_1' => 23, '6_1' => 3.3, '4_1' => 23.2, )*/