1

I've a multidimesional array in my PHP code ...

$wayPoints = $_POST['wayPoints'];
print_r ($wayPoints);

that returns

[["1dcb4f6575fbf5ee4ebd542d5981a588",7.67468,44.91085],["7503c3e97935960d0f7abcb6f7ad70f4",7.67614,44.90977]]

I need to get the values at index = 1 and index = 2 in the array: if I try to get the value

7.67468

using

print_r ($wayPoints[0][1]);

I obtain

Notice: Uninitialized string offset: 1 

as error

Using

print_r ($wayPoints[0]);

I obtain

[

as error

Suggestions?

Cesare
  • 1,629
  • 9
  • 30
  • 72
  • 2
    that's not an array. it's a string containing a json-encoded array. you need to decode that string, THEN it's just a php array, like any other array. – Marc B Sep 12 '16 at 20:47
  • 1
    you have stings in your array –  Sep 12 '16 at 20:47
  • 1
    it seems that $wayPoints[0] is a string. Are you sure you should not parse the response first? – mabe02 Sep 12 '16 at 20:48

1 Answers1

2

As definitely your $_POST['wayPoints'] is a json_encoded string, try this part of code:

// decode your json-string to array
$wayPoints = json_decode($_POST['wayPoints'], true);
// if you want to check what you have:
print_r($wayPoints)
// echo required item:
echo $wayPoints[0][1];

More about json you can find here, in Documentation, or with google.

u_mulder
  • 54,101
  • 5
  • 48
  • 64