如何从数组php中获取值

时间:2015-08-09 05:07:12

标签: php arrays multidimensional-array

以下是print_r($_GET);

的价值

输出

    Array(
    [prevurl() ] => Array(
        [taxirate] => 3500[Source] => Land[T] => Yes[TId] => 10[dtaxirate] => 4500[TD] => Yes[TDId] => 14[modeset] => minivan[minivanrate] => 400[Minivan] => Yes[MinivanId] => 6[FirstSearch] => FirstSearch[returnTrip] => yes[return -one] => No[Trip] => OneWay[TravelFrom] => Destination[TravelTo] => Pak[TravelDay] => 2015 - 08 - 16[TotalCount] => 1[Mode] => [Both] => [BothReturn] => 2015 - 08 - 17[Adults] => 1[Childs] => [Kids] => [Babies] =>
    )
)

我试过

echo $_GET['prevurl']['taxirate'];但它不起作用。

如何获得taxirate

的值
<input type="hidden" value="Array
(
    [taxirate] => 3500
    [Source] => Land
    [T] => Yes
    [TId] => 10
    [dtaxirate] => 4500
    [TD] => Yes
    [TDId] => 14
    [modeset] => minivan
    [minivanrate] => 400
    [Minivan] => Yes
    [MinivanId] => 6
    [FirstSearch] => FirstSearch
    [returnTrip] => yes
    [return-one] => No
    [Trip] => OneWay
    [TravelFrom] => Hat Yai Airport
    [TravelTo] => Pak Bara
    [TravelDay] => 2015-08-16
    [TotalCount] => 1
    [Mode] => 
    [Both] => 
    [BothReturn] => 2015-08-17
    [Adults] => 1
    [Childs] => 
    [Kids] => 
    [Babies] => 
)
" name="prevurl">

更新:

注意:

这是我在上一页的input

<input type="hidden" value="Array
(
    [taxirate] => 3500
    [Source] => Land
    [T] => Yes
    [TId] => 10
    [dtaxirate] => 4500
    [TD] => Yes
    [TDId] => 14
    [modeset] => minivan
    [minivanrate] => 400
    [Minivan] => Yes
    [MinivanId] => 6
    [FirstSearch] => FirstSearch
    [returnTrip] => yes
    [return-one] => No
    [Trip] => OneWay
    [TravelFrom] => Hat Yai Airport
    [TravelTo] => Pak Bara
    [TravelDay] => 2015-08-16
    [TotalCount] => 1
    [Mode] => 
    [Both] => 
    [BothReturn] => 2015-08-17
    [Adults] => 1
    [Childs] => 
    [Kids] => 
    [Babies] => 
)
" name="prevurl()">

实际上输入是一个数组

2 个答案:

答案 0 :(得分:0)

假设数组值存储在变量中,我会尝试:

<?php
foreach ($array_data as $key=>$value)
{
    if($key == "prevurl")
    {
        foreach ($value as $key1=>$value1)
        {
            switch($key1)
            {
                case "taxirate":
                    $taxirate = $value1;
                break;
            }
        }
    }
}
?>

但我同意Rasclatt的看法。那个数组看起来奇怪/奇怪。

编辑:您的原始问题看起来像一个多维数组,但您的编辑看起来并不是多维的。我的答案来自你的原始代码。

答案 1 :(得分:0)

只需将隐藏的输入字段名称更改为name="prevurl"即可。并将您的出租车价值视为:

$_GET['prevurl']['taxirate'];