1

I have encoded a set of multidimensional array from the php and i echo to the ajax. Now the response looks like the following

 Array
(    
    [0]=>Array
         ([messagebody]=>hello
          [senderid]=>2
          [receiverid]=4
          )
   [1]=>Array
         ([messagebody]=>how are you
          [senderid]=>4
          [receiverid]=2
          )
    )

Please how do i access this array in javascript to get the messagebody?

June7
  • 19,874
  • 8
  • 24
  • 34

1 Answers1

3

You shouldn't be print_r() your arrays as this it produces human readable output, nothing JS can deal with easily nor out of the box. Instead you should use i.e. JSON and pass your arrays in that form to JS:

echo json_encode($my_array, JSON_UNESCAPED_UNICODE);
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141