Code:
$result = cfgdb_read('cfg_audiodev', cfgdb_connect(), $i2sDevice);
sysCmd('sed -i "s/dtparam=audio=on/dtparam=audio=off/" ' . '/boot/config.txt');
sysCmd('echo dtoverlay=' . $result[0]['driver'] . ' >> ' . '/boot/config.txt');
If instead of using echo we use sed in the last line:
Code:
sed -i '/dtparam=audio=off/a dtoverlay=test' /boot/config.txt
it will react the way you describe, the dtoverlay line will be added after dtparam=audio=off