3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 0 => "(Type): multiplechoice", 1 => "(Question): Which of the following is true about pre-test imagery?", 2 => "(A): People with a cranial fault can visualize the muscle being strong and make it go strong, while people without a cranial faults cannot.", 3 => "(B): If Governing Vessel (GV) 20 tests weak, it also means they have a cranial fault. This is on the midline at the apex of the head.", 4 => "(C): The three most common cranial faults are TMJ, occiput and sphenoid", 5 => "(D): All of the above", 6 => "(Correct): D", 7 => "(Type): multiplechoice", 8 => "(Question): Which of the following is not true about the TMJ?", 9 => "(A): Every single TMJ nerve pathway goes through the mesencephalon in the midbrain.", 10 => "(B): When you work on the TMJ it is a neurological back-up for the entire body.", 11 => "(C): To correct press on the glabella with one hand as you press of the back of the head with the other as the patient touches the chin with two fingers and breathes in only one time.", 12 => "(Correct): C", 13 => "(Type): truefalse", 14 => "(Question): To test for a deficiency of the four primary neurotransmitters, point the edge of a magnet straight in at each of the four corresponding cranial bon ▶", 15 => "(A): True", 16 => "(B): False", 17 => "(Correct): A"); //Var_dump($arr); $j=-1; $res = array(); Foreach($arr as $value){ If(preg_match("/\(Type\)/", $value, $match)){ $j++; } preg_match("/\((.*?)\): (.*)/", $value, $match); $res[$j][$match[1]]= $match[2]; } Var_dump($res);
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.6 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
array(3) { [0]=> array(7) { ["Type"]=> string(14) "multiplechoice" ["Question"]=> string(54) "Which of the following is true about pre-test imagery?" ["A"]=> string(134) "People with a cranial fault can visualize the muscle being strong and make it go strong, while people without a cranial faults cannot." ["B"]=> string(128) "If Governing Vessel (GV) 20 tests weak, it also means they have a cranial fault. This is on the midline at the apex of the head." ["C"]=> string(66) "The three most common cranial faults are TMJ, occiput and sphenoid" ["D"]=> string(16) "All of the above" ["Correct"]=> string(1) "D" } [1]=> array(6) { ["Type"]=> string(14) "multiplechoice" ["Question"]=> string(49) "Which of the following is not true about the TMJ?" ["A"]=> string(78) "Every single TMJ nerve pathway goes through the mesencephalon in the midbrain." ["B"]=> string(74) "When you work on the TMJ it is a neurological back-up for the entire body." ["C"]=> string(178) "To correct press on the glabella with one hand as you press of the back of the head with the other as the patient touches the chin with two fingers and breathes in only one time." ["Correct"]=> string(1) "C" } [2]=> array(5) { ["Type"]=> string(9) "truefalse" ["Question"]=> string(152) "To test for a deficiency of the four primary neurotransmitters, point the edge of a magnet straight in at each of the four corresponding cranial bon ▶" ["A"]=> string(4) "True" ["B"]=> string(5) "False" ["Correct"]=> string(1) "A" } }

preferences:
163.58 ms | 407 KiB | 197 Q