-1

I have a .json file with some data I'm trying to extract. What I need to know is how I would go about making the below variable dynamic.

$MapData['MapData']['0,0']['type'];

What I need to know is how I would replace the 0,0 with $x,$y variables. I've tried to use variable as a variable name.

$MapString = "MapData['MapData']['".$x.",".$y."']['type']";
$MapStringData = $$MapString;

I was unsuccessful in getting this to work. Is there something I'm missing or not doing right?

Born2DoubleUp
  • 109
  • 1
  • 10

1 Answers1

0

If you can rely on the last cell having the highest row/column number as the key, then you first can extract the keys for the MapData, and with the last (usingend) element split it using explode() with a ,. This uses list() to assign the two values to the rows and column fields...

$cells = array_keys($MapData['MapData']);
list($MapRows, $MapCols) = explode(",", end($cells));
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55