$ifnames = array_keys($iflist);[...]$wanif = count($ifnames) > 1 ? $ifnames[1] : '';[...]$lanif = count($ifnames) > 0 ? $ifnames[0] : '';
If you replace e.g. mismatch0 => em0 and mismatch1 => em1 doesn't that mean the interface count changes during reboot? The replace is sticky, but you are in trouble if em0 or em1 is missing.