I am trying to group my array values based on the array keys then print the result in the UI. I am stuck here for hours now.
Here is the array I need to format:
Array
(
[checklist1] => major
[result_audit1] => 1
[checklist2] => minor
[result_audit2] => 2
[checklist3] => pico
[result_audit3] => 3
[checklist4] => goodpoints
[result_audit4] => 4
[submit] => Submit Now
)
Here is what I have tried so far but it is misaligned and not a proper result of the array.
foreach($n_data as $key => $data)
{
$array['checklist'][$i] = array(
'selected' => $n_data[$key],
'result_audit' => $n_data[$key]
);
$i++;
}
Desired array:
Array
(
[checklist] => Array
(
[0] => Array
(
[selected] => major
[result_audit] => 1
[origin] => checklist1
)
[1] => Array
(
[selected] => minor
[result_audit] => 2
[origin] => checklist2
)
))
$iwas never declared in your snippet? You only ever tried to access it and increment it. LF00 is correct, you will have fewer headaches if you improve your html form -- this way the payload will be easier to access.sscanf()offers the most elegant solution: 3v4l.org/aYY8E, but I cannot post an answer because this page is closed.name="submit"from your form button so that it's value is not included in the submission payload.sscanf()is a very good idea. I can see here that you like that function ;-)