0

I am perplexed in getting the GET Variables for the url of this specific page.

The URL is :-

http://thisthat.com/category/?field_issue_month_value%5Bvalue%5D%5Byear%5D=2013&field_issue_month_value%5Bvalue%5D%5Bmonth%5D=10

I am trying to output both of these GET variables.

I tried following ways and it failed :(

echo urldecode("field_issue_month_value%5Bvalue%5D%5Bmonth%5D");
     [field_issue_month_value]
echo $_GET['field_issue_month_value[value][year][0]'];
echo $_GET["field_issue_month_value[value][month]"];

echo urldecode($_GET['field_issue_month_value%5Bvalue%5D%5Bmonth%5D']);

The Var_dump is as follows:-

{ ["field_issue_month_value"]=> array(1) { ["value"]=> array(2) { ["year"]=> string(4) "2013" ["month"]=> string(2) "10" } } ["q"]=> string(19) "Page-Name" }
2
  • 2
    Why are you trying to guess when print_r($_GET) will show you exactly what's going on?
    – Jon
    Dec 24, 2013 at 9:44
  • I need to put a condition on what field_issue_month_value[value][month] shows, hence I need that value.
    – Steve
    Dec 24, 2013 at 9:49

1 Answer 1

1

If $_GET contains an array, you should access the data the following way:

Your array is multidimensional, thus you need several indeces to get that data:

$_GET['field_issue_month_value']['value']['year'] ;

Otherwise using $_GET['field_issue_month_value[value][year][0]']; you just go 1-level deep, using one string as an index.


UPD: This example works fine for me:

parse_str(urldecode('field_issue_month_value%5Bvalue%5D%5Byear%5D=2013&field_issue_month_value%5Bvalue%5D%5Bmonth%5D=10'), $r);

echo $r['field_issue_month_value']['value']['month'] . "<br/>" ;
echo $r['field_issue_month_value']['value']['year'] . "<br/>" ;
3
  • Thanks Jari. But it just shows the first number. For example if the year of the GET variable is 2013, it just shows 2. Any idea?
    – Steve
    Dec 24, 2013 at 9:48
  • Just a sec, I will try to figure it out.
    – sybear
    Dec 24, 2013 at 9:50
  • Try $_GET['field_issue_month_value']['value']['year'] ;in case it does not work, could show us output of var_dump($_GET) ?
    – sybear
    Dec 24, 2013 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.