-2

I've got this url:

http://web.com/script.php?identifiers%5Bmc%5D%5Bnick%5D=name1&identifiers%5Bcs%5D%5Bnick%5D=name2&identifiers%5Bcs%5D%5Bpassword%5D=mypass

so i will get array like this:

[identifiers] => Array
    (
        [mc] => Array
            (
                [nick] => name1
            )

        [cs] => Array
            (
                [nick] => name2
                [password] => mypass
            )

    )

How do I take value name1 and put into variable $mc_name?

Kypros
  • 2,997
  • 5
  • 21
  • 27
Patrik Staron
  • 331
  • 1
  • 9

2 Answers2

2

That's a simple array containing another array so you can simply specify multiple indexes for included array:

$mc_name = $_GET['identifiers']['mc']['nick'];

To better understand how it works think of it like assigning each array first to a variable like:

$identifiers = $_GET['identifiers'];
$mc_array = $identifiers['mc'];
$mc_name = $mc_array['nick'];

which will essentially do the same thing at once, without the need to specify multiple variables and arrays.

Kypros
  • 2,997
  • 5
  • 21
  • 27
0

Start with:

identifiers = $_GET['identifiers']

If you know the key names, then simply:

$mc_name = $identifiers['mc']['nick']

If you know it's the first value or the first value, then you can:

$mc_name = array_shift($identifiers);  // get the 'mc' array
$mc_name = array_shift($identifiers);  // get the 'nick' value

Not that array_shift will actually remove the elements from the original array.

Oz Solomon
  • 2,969
  • 23
  • 22