- print_r: documentation ( source)
- in_array: documentation ( source)
- file: documentation ( source)
<?php
$environments = [
'qa-only' => [],
'prd-only' => [],
'both' => []
];
$qa = file('qa.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$prd = file('prd.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($prd as $key => $env) {
if(in_array($env, $qa)) {
$environments['both'][] = $env;
} else {
$environments['prd-only'][] = $env;
}
}
foreach($qa as $key => $env) {
if(in_array($env, $prd) && !in_array($env, $environments['both'])) {
$environments['both'][] = $env;
} else {
$environments['qa-only'][] = $env;
}
}
print_r($environments);