gpt4 book ai didi

php - 查询字符串处理

转载 作者:可可西里 更新时间:2023-10-31 22:59:33 25 4
gpt4 key购买 nike

在进行一些查询字符串处理时,我偶然发现了这个:

<?php
$in='a=6&b=7&8=c';
parse_str($in,$qs);
$out=array_merge($qs,array('9'=>'d'));
print_r($out);
?>

我们得到:

Array
(
[a] => 6
[b] => 7
[0] => c
[1] => d
)

代替:

Array
(
[a] => 6
[b] => 7
[8] => c
[9] => d
)

我理解为什么会发生这种情况('8' 和 '9' 被视为数字键)但我不高兴我必须长期这样做。

一定有办法让它变得简单。您如何对查询字符串进行切片、切 block 和处理?

最佳答案

考虑对数组使用 UNION 运算符

$out=$qs+array('9'=>'d');
print_r($out);

关于php - 查询字符串处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3523853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com