0

我正在使用 URL 来获取 URL 中存储/显示的数据。我使用 $_REQUEST['v_name'] 获取变量的所有值,但如果 URL 中有一个数组,我该如何检索该值。

例如:

WWW.example.com/rooms?&hid=213421&type=E

我得到了隐藏的值并使用

$hid=$_REQUEST['hid'];

但在 URL 中,如:

 WWW.example.com/rooms?&rooms=2&rooms[0].adults=2&rooms[0].children=0&rooms[1].adults=2&rooms[1].children=0

我如何检索每个房间中成人和儿童的价值。

请帮忙。提前致谢

4

2 回答 2

1

You could also try something like this, since most of your original $_REQUEST isn't really an array (because of the .s in between each key/value pair):

<?php
$original_string = rawurldecode($_SERVER["QUERY_STRING"]);
$original_string_split = preg_split('/&/', $original_string);
$rooms = array();
foreach ($original_string_split as $split_one) {
  $splits_two[] = preg_split('/\./', $split_one);
}
foreach ($splits_two as $split_two) {
  if (isset($split_two[0]) && isset($split_two[1])) {
    $split_three = preg_split('/=/', $split_two[1]);
    if (isset($split_three[0]) && isset($split_three[1])) {
      $rooms[$split_two[0]][$split_three[0]] = $split_three[1];
    }
  }
}
// Print the output if you want:
print '<pre>' . print_r($rooms, 1)  . '</pre>';
于 2013-10-26T07:37:44.537 回答
0
$valuse = $_GET;

foreach ($valuse as $key=>$value)
{
     echo $key .'='. $value. '<br/>';
}
于 2013-10-26T06:56:28.703 回答