Chirag Nagpal
Chirag Nagpal

Reputation: 729

How to fetch URL variable array using $_REQUEST['variable name']

I am using a URL to fetch data stored/shown within URL. I get all the value of variable using $_REQUEST['v_name'] but if there is a array in URL how can i retrieve that value.

For Example:

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

I got the value hid and type using

$hid=$_REQUEST['hid'];

but in URL like:

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

how can i retrieve value of adults and children in each room.

please help. Thanks in Advance

Upvotes: 0

Views: 1802

Answers (2)

jerdiggity
jerdiggity

Reputation: 3665

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>';

Upvotes: 1

Osama Jetawe
Osama Jetawe

Reputation: 2705

$valuse = $_GET;

foreach ($valuse as $key=>$value)
{
     echo $key .'='. $value. '<br/>';
}

Upvotes: 0

Related Questions