3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[{ "id": "5b2a4b0287bc2c082ebc2897", "test_name": "BSF", "test_type": "Pathology", "cost": "100" }, { "id": "5b2a4ac63db998081e7f6c97", "test_name": "Brain & PNS", "test_type": "Radiology", "cost": "1000" }, { "id": "5b2a4ac63db998081e22336c97", "test_name": "BPNS", "test_type": "Radiology", "cost": "1000" }]'; $arr = json_decode($json,true); $type = array_column($arr, "test_type"); Foreach(array_unique($type) as $t){ $new[$t] = array_intersect_key($arr, array_intersect($type, [$t])); } extract($new); Var_dump($Radiology, $Pathology);

preferences:
27.73 ms | 411 KiB | 5 Q