Evening!
I'm really clueless about this, thought to myself I'd resort to y'all for some guidance. I have an array, directly fetched from a MySQL table, looks like this:
array(106) {
[...]
[32]=>
array(4) {
["x"]=>
int(3)
["y"]=>
int(5)
["z"]=>
int(7)
["image"]=>
string(14) "ground/grass/1"
}
[33]=>
array(4) {
["x"]=>
int(3)
["y"]=>
int(5)
["z"]=>
int(8)
["image"]=>
string(16) "objects/nature/1"
}
[34]=>
array(4) {
["x"]=>
int(4)
["y"]=>
int(5)
["z"]=>
int(7)
["image"]=>
string(14) "ground/grass/1"
}
[...]
}
What I want to do is to merge the elements’ images where the x and y keys are equal, creating a new array where the z values becomes keys. There can be more than two elements with the same x and y values, but the z values are never the same for these elements. Kinda hard to explain, but the desired output looks something like this:
array(106) {
[...]
[32]=>
array(4) {
["x"]=>
int(3)
["y"]=>
int(5)
["z"]=>
int(7)
["image"]=>
array(2) {
[7]=>
string(14) "ground/grass/1"
[8]=>
string(16) "objects/nature/1"
}
}
[34]=>
array(4) {
["x"]=>
int(4)
["y"]=>
int(5)
["z"]=>
int(7)
["image"]=>
string(14) "ground/grass/1"
}
[...]
}
I'd love to provide you with my progress so far, but fact is I am clueless on this one. The MySQL table looks like this:
| id | x | y | z | image |
+----+----+----+----+--------------------+
| 1 | 3 | 5 | 7 | 'ground/grass/1' |
| 2 | 3 | 5 | 8 | 'objects/nature/1' |
Sorry for the long question. Thanks in advance!