Reputation: 278
In PHP I can define a table/array like this:
$string = 'foo';
$array = array();
$array[$string] = 'bar';
print_r($array); // Result: Array ( [foo] => bar )
so I used the $string
to define the key of the first array entry.
How can I accomplish the same in lua?
Edit:
And can I access the result the like this?
print($array[$string]); // Result: bar
Upvotes: 0
Views: 267
Reputation: 3467
Like this:
myArray = {}
someString = "foo"
myArray[someString] = "bar"
Read more about tables in Lua here.
Upvotes: 1