Creating a multidimensional array
Posted: Mon Jul 02, 2012 4:58 am
Instead of quering the database multiple times, I was thinking of querying it once and storing all the values in an array. Theres 2 ways I've been thinking of setting it up, I'm wondering if there is a 'right way' to do it or both ways are acceptable. Also, which one you think will be the easier array to handle when dealing with multiple (for example 100) entries
I will use weapons as an example. Say a player has a lot of weapons in his inventory, and they all have stats. Those stats are:
-Name
-Minimum Damage
-Maximum Damage
-Description
I am leaning towards the first idea, as it looks more organised, but would like to get some feedback! I've never really dealt with multidimensional arrays.
Array idea 1
The first idea I had was to make each weapon name an array and each stat of the weapon an index.
Array
(
[Name] => Array
(
[mindamage] => 3
[maxdamage] => 10
[Description] => "A blunt sword"
)
)
Array idea 2
The second idea was to make each index of the first array the name of each weapon stat, then each index inside of them a numeric array
Array
(
[Name] => Array
(
[0] => Blunt Sword
[1] => Steel Battleaxe
[2] => AK-47
)
[mindamage]
(
[0] => 3
[1] => 10
[2] => 200
)
[maxdamage]
(
[0] => 5
[1] => 18
[2] => 500
)
[description]
(
[0] => "A blunt sword
[1] => "A steel battleaxe"
[2] => "A machine gun
)
)
I will use weapons as an example. Say a player has a lot of weapons in his inventory, and they all have stats. Those stats are:
-Name
-Minimum Damage
-Maximum Damage
-Description
I am leaning towards the first idea, as it looks more organised, but would like to get some feedback! I've never really dealt with multidimensional arrays.
Array idea 1
The first idea I had was to make each weapon name an array and each stat of the weapon an index.
Array
(
[Name] => Array
(
[mindamage] => 3
[maxdamage] => 10
[Description] => "A blunt sword"
)
)
Array idea 2
The second idea was to make each index of the first array the name of each weapon stat, then each index inside of them a numeric array
Array
(
[Name] => Array
(
[0] => Blunt Sword
[1] => Steel Battleaxe
[2] => AK-47
)
[mindamage]
(
[0] => 3
[1] => 10
[2] => 200
)
[maxdamage]
(
[0] => 5
[1] => 18
[2] => 500
)
[description]
(
[0] => "A blunt sword
[1] => "A steel battleaxe"
[2] => "A machine gun
)
)