How does PHP realize URI variable matching and modification lightly?

for example, I have an address:
abc.com/?abc=123&xyz=987
I want to change the abc variable to 456, keep the other variables as they are, and return the new URI address.
the method currently used is regular matching:

function uridis($act,$val){return preg_replace("/(^|&)".$act."\=(?:.*?)($|&)/i","\1".$act."=".$val."\2",$_SERVER["QUERY_STRING"]);}

call in the PHP file:

uridis("abc",456);

if implemented in this way, regular expressions take up about 387KB memory.
and replace with str_replace:

function uridis($act,$val){return trim(str_replace("&".$act."=".$_GET[$act]."&","&".$act."=".$val."&","&".$_SERVER["QUERY_STRING"]."&"),"&");}

takes up more memory, about 392KB. Don"t even think about the cycle $_ GET, you can"t read it at all.
because I need to generate dozens of replaced URI, programs on the page that are very efficient.
so do you have a lighter solution? Thank you very much!

Mar.15,2021

function uridis($act,$val){
    $get=$_GET;
    $get[$act] = $val;
    return http_build_query($get);
}

there are only dozens of replacements, regardless of performance

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be9bfd-31987.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be9bfd-31987.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?