-1

I'm looking to read JSON array using PHP. I'm using php file_get_contents to read the JSON array.

So, here is how my array look like,My array

Can anyone tell me how can I read all the array?

halfer
  • 19,824
  • 17
  • 99
  • 186
Jalon Juanis
  • 65
  • 12

2 Answers2

4

return your array with json_encode($array) it will return a JSON Object.

Mohamed Nizar
  • 780
  • 9
  • 30
1

Building on @mohamed-nizar,

filename.php:

<html>
<head>
<script>
var json = <?php json_encode(file_get_contents('array.php')); ?>;
</script>
</head>
<body>
</body>
</html>

For converting JSON to and Javascript Array(), check this thread: How to convert JSON to Array But there's really no reason to do so, it's better to just use the JSON.

Community
  • 1
  • 1
Anuga
  • 2,619
  • 1
  • 18
  • 27