Php 如何使用数组(关联)作为标题?

Php 如何使用数组(关联)作为标题?,php,arrays,url,redirect,header,Php,Arrays,Url,Redirect,Header,如果url为example.com/redirect.php?source=test,则应该重定向到google.com,但它不起作用。如果我将数组键更改为1,并将位置更改为$testurl[1],它就可以工作了。为什么它使用索引数组而不是关联数组?假设您有一个数组$testurl,其中有一个元素google: $testurl=[ '谷歌'=>'https://google.pl' ]; 然后你可以这样使用它: if($source==“test”){ 标题(“位置:$testurl[goo

如果url为example.com/redirect.php?source=test,则应该重定向到google.com,但它不起作用。如果我将数组键更改为1,并将位置更改为$testurl[1],它就可以工作了。为什么它使用索引数组而不是关联数组?

假设您有一个数组
$testurl
,其中有一个元素
google

$testurl=[
'谷歌'=>'https://google.pl'
];
然后你可以这样使用它:

if($source==“test”){
标题(“位置:$testurl[google]”;
}

if($source==“test”){
标题(“位置:{$testurl['google']}”);
}
或者在我看来最好的选择,像这样:

if($source==“test”){
标题('Location:'.$testurl['google']);
}
这只是它的定义:

有一句话:

if ($source=="test") {
header("Location: $testurl['google']"); 
}

假设您有一个数组
$testurl
,其中包含一个元素
google

$testurl=[
'谷歌'=>'https://google.pl'
];
然后你可以这样使用它:

if($source==“test”){
标题(“位置:$testurl[google]”;
}

if($source==“test”){
标题(“位置:{$testurl['google']}”);
}
或者在我看来最好的选择,像这样:

if($source==“test”){
标题('Location:'.$testurl['google']);
}
这只是它的定义:

有一句话:

if ($source=="test") {
header("Location: $testurl['google']"); 
}

它的输入法,用作
if($source==“test”){$url=$testurl['google'];header(“Location:$url”);}
它的输入法,用作
if($source==“test”){$url=$testurl['google'];header(“Location:$url”);}
谢谢,它能用!我用了最好的选择。谢谢,很有效!我用了最好的选择。