0

Say you are on this page: profile.php?user=1&wicked=3

To get an array like:

Array
(
    [user] => 1
    [wicked] => 3
)

How do I simply get the first or second value of the array? So if I want the second, I would get: wicked=3? Is it something with a foreach loop?

4
  • 1
    You should probably explain what you are trying to do because depending on the order of the parameters is probably not the greatest idea. Commented Feb 20, 2013 at 18:05
  • foreach will help but as Paolo said you might be doing something wrong Commented Feb 20, 2013 at 18:06
  • Unless you're looking for $_GET['wicked'] ? Commented Feb 20, 2013 at 18:07
  • I want to determine it by the number of the variable. Like first, second, third, etc. Commented Feb 20, 2013 at 18:08

1 Answer 1

3

If I get you right, you would like to use number-indexed array.

$new_ar = array_values($_GET) ; //["user"=>"1", "wicked"=>"3"] ;
echo $new_ar[1] ; // echoes 2nd value - "3"
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! This is exactly what I was looking for. $get_values = array_values($_GET); $get_keys = array_keys($_GET); $get = $get_keys[1] . "=" . $get_values[1]; echo $get;

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.