1

I just inherited some code, and have not seen this format before. Here's an array:

$arrayWeather = array('weatherParameters' => array(
                                                   'wspd'  => $_GET['wspd']  == 'wspd',
                                                   'wdir'  => $_GET['wdir']  == 'wdir',
                                                   'waveh' => $_GET['waveh'] == 'waveh'));

I've never seen this before; what exactly does this mean?

'wspd'  => $_GET['wspd']  == 'wspd'

Is it a shortcut if statement, saying if _$GET['wspd'] exists, set the array key called wspd to the literal value wspd? Or something else entirely?

EmmyS
  • 11,892
  • 48
  • 101
  • 156

4 Answers4

9

$_GET['wspd'] == 'wspd' is a boolean, and the value of that boolean is assigned to the wspd key in the subarray.

SO if $_GET['wspd'] is "wspd", it will be the same as

 $arrayWeather = array('weatherParameters' => array(
                                               'wspd'  => true,
                                                etc...
Nanne
  • 64,065
  • 16
  • 119
  • 163
  • Thank you. I've never seen that particular shorthand before. – EmmyS Feb 24 '11 at 15:47
  • Well, compare it to anyplace where you would normally have a boolean, like an `if`: `if($_GET['wspd'] == 'wspd')` would look a lot more familliar, wouldn't it? Now that comparison results in a boolean, which you can save somewhere :) – Nanne Feb 24 '11 at 15:50
1

It gives the key called 'wspd' the result of the equation $_GET['wspd'] == 'wspd', which is either true or false.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
1

I know the 'wspd' => $_GET['wspd'] just sets the value of the 'wspd' key in the array now the second part i've never seen.

8vius
  • 5,786
  • 14
  • 74
  • 136
1

Well... it's quite simple. You just assign the result of expression $_GET['wspd'] == 'wspd' (a boolean true or false) to the wspd index of $arrayWeather.

Crozin
  • 43,890
  • 13
  • 88
  • 135