I have this code i am using to write json to a file
<?php
require_once 'vendor/autoload.php';
$faker = Faker\Factory::create();
function getAge($start = 18, $end = 100, $repeat = 20){
    $result = null;
    static $ages = array();
    if ( empty($ages) ) {
        for ($i= $start; $i <= $end; $i++) {
            for($j = 0; $j < $repeat; $j++)
            $ages[] = $i;
        }
    }
    $index = rand(0, count($ages));
    $result = $ages[ $index ];
    unset($ages[ $index ]);
    $ages = array_values($ages);
    return $result;
}
$superstars = array("Adam Cole","Finn Balor","Pete Dunne","Jordan Devlin","Noam Dar");
$fan_favourite_superstar_name = $superstars[ mt_rand( 0, count($superstars) -1 ) ];
$cities = array("London","Manchester","Leeds","Bristol");
$fan_location = $cities[ mt_rand( 0, count($cities) -1 ) ];
$the_models = array("Iphone","Nokia","Huawei","Samsung");
$fan_phone_model = $the_models[ mt_rand( 0, count($the_models) -1 ) ];
for ($x = 1; $x <= 100; $x++) {
    echo $x;
$array = Array (
    "$x" => Array (
        "id" => uniqid(),
        "fan_favourite_superstar_name" => $fan_favourite_superstar_name,
        "fan_location" => $fan_location,
        "fan_phone_model" => $fan_phone_model,
        "fan_name" => $faker->name,
        "fan_age" => getAge(),
        "fan_comments" => $faker->text,
        "fan_picture" => rand(1,500),
        "last_updated" => time() + rand(1,1000),
    )
);
// encode array to json
$json = json_encode(array('fans' => $array));
//write json to file
if (file_put_contents("data.json", $json))
    echo "JSON file created successfully..."."<br/>";
else 
    echo "Oops! Error creating json file...";
}
?>
When i run, only the first line is written. Why are the other lines not being written?.
 
     
    