i convert json file to array but it give me error in foreach invalid argument
<?php
require 'vendor/autoload.php';
$client = new MongoDB\Client;
$test = $client->test;
$createCollection = $test->restaurants;
$string = file_get_contents("D:\Database\primer-dataset.json");
$json_a = json_decode($string, true);
foreach ($json_a as $id => $item)
{
$createCollection->insert( $item);
?>
Since it says invalid argument
, $string
is probably not valid JSON. Check the contents of $string
and $json_a
to see what exactly is happening.