Reputation: 1331
This is killing me, for the life of me i can not seem to figure out how to get this to work, or why it doesn't work in the first place.
Here is what i'm trying to do:
here is my variables declaration:
$locale = 'US';
$realm = 'magtheridon';
$character = 'billymayys';
here is my array declaration:
$my_array = ( 'L' => $locale, 'R' => $realm, 'C' => $character );
I am new to php and from what i can tell this should create an array who would print out to:
Array(
[L] => US,
[R] => magtheridon,
[C] => billymayys,
);
But it doesn't.
What is the proper way to create an array, whos index i can name and then assign variables to the values of those indexs?
The array declaration:
$my_array = ( 'L' => 'US', 'R' => 'magtheridon', 'C' => 'billymayys' );
Works but i do not understand why i cannot dynamically assign the values using variables.
Please help! Thanks.
Upvotes: 3
Views: 872
Reputation: 28911
You just have a minor syntax error, missing the array
keyword.
Change:
$my_array = ( 'L' => $locale, 'R' => $realm, 'C' => $character );
To:
$my_array = array( 'L' => $locale, 'R' => $realm, 'C' => $character );
Or:
$my_array = [ 'L' => $locale, 'R' => $realm, 'C' => $character ]; // PHP 5.4+
Working example: http://3v4l.org/d2UWM
Upvotes: 5
Reputation: 695
You need to use the array
keyword:
$my_array = array( 'L' => $locale, 'R' => $realm, 'C' => $character );
Not sure why the second one would work!
Upvotes: 0