So I've made a query which retrieves some test data, and I need to sort this data in a array.
The data can look like this:
Table data as text
testsuitecollectionId testsuiteId testcaseId Status
17 38 443 passed
457 39 444 passed
455 40 447 passed
455 40 448 passed
455 40 449 passed
34 1216 960 passed
457 1216 961 passed
457 1216 962 passed
34 1216 964 passed
456 1216 966 na
457 124 975 passed
457 124 976 passed
457 124 977 passed
457 142 1033 passed
457 464 1070 passed
457 464 1071 passed
457 464 1072 passed
455 687 1345 passed
34 688 1346 passed
34 690 1351 passed
34 690 1352 passed
34 691 1355 passed
34 691 1356 passed
34 691 1357 passed
34 691 1358 passed
34 691 1359 passed
34 692 1361 failed
34 693 1362 failed
I do have an array with all the TestSuiteCollectionIds needed called $tsc.
What I'm trying to do is to create a array / JSON (don't know whats best) looking like this:

So I'm trying to somehow get a structure like in the image, by sorting the data, so I can use it later on in a excel.
I tried to create a foreach loop but got stuck.
This creates a array in the style of this:
$ => Array (2)
(
| ['454'] => Array (9)
| (
| | ['0'] = String(2) "38"
| | ['1'] = String(2) "39"
| | ['2'] = String(2) "40"
| | ['3'] = String(2) "40"
| | ['4'] = String(2) "40"
| | ['5'] = String(4) "1216"
| | ['6'] = String(4) "1216"
| | ['7'] = String(4) "1216"
| | ['8'] = String(4) "1216"
)
| ['234'] => Array (9)
| (
| | ['0'] = String(2) "38"
| | ['1'] = String(2) "39"
| | ['2'] = String(2) "40"
| | ['3'] = String(2) "40"
| | ['4'] = String(2) "40"
| | ['5'] = String(4) "1216"
| | ['6'] = String(4) "1216"
| | ['7'] = String(4) "1216"
| | ['8'] = String(4) "1216"
)
)
I made the array with this code
$tsc_arr = $ts_arr = $tc_arr = array();
foreach ($tsc as $id) {
foreach ($test_data as $key) {
if($key['TestSuiteCollectionId'] = $id){
$tsc_arr[$key['TestSuiteCollectionId']][] = $key['TestSuiteId'];
}
}
}
But I'm a bit stuck on how to make the test suite unique also. So I have unique ID testsuitecollectionId --> unique testsuiteId --> testcaseId = Status, testcaseId = Status
Would it be easiest to make this as a JSON or array or is there another way I don't know?
Think I might have made a solution, but I don't know if this can be done more pretty?
foreach ($tsc as $id) {
foreach ($test_data as $key) {
if($key['TestSuiteCollectionId'] = $id){
$tsc_arr[$key['TestSuiteCollectionId']][$key['TestSuiteId']][] = $key['TestCaseId'].";".$key['StatusName'];
}
}
}
This part $tsc_arr[$key['TestSuiteCollectionId']][$key['TestSuiteId']][]
makes all the TestCase data come into the right same testsuite and the testsuites are unique.