I have wrong output from my fixture template

53 Views Asked by At
<?php

$filePath = __DIR__ . '/../../data/cities.csv';
$file = fopen($filePath, 'r');

$cities = [];
$index = 0;

// Skip header line
fgetcsv($file);

while (($data = fgetcsv($file)) !== FALSE) {
    $cityKey = 'city' . $index;

    // Если мы впервые видим city0, пропустить эту итерацию и перейти к следующей
    if ($cityKey === 'city0') {
        $index++;
        continue;
    }

    $cities[$cityKey] = [
        'name' => $data[0],
        'latitude' => $data[1],
        'longitude' => $data[2],
    ];

    $index++;
}

fclose($file);

return $cities;

i have such fixture template, this template creates such

   'city0' => [
        'city1' => [
            'name' => 'Абакан',
            'latitude' => '53.7223661',
            'longitude' => '91.4437792',
        ],
        'city2' => [
            'name' => 'Абдулино',
            'latitude' => '53.6778096',
            'longitude' => '53.6473115',
        ],

structure, to be correct i need to remove 'city0' => [, how i can do this?

  if ($cityKey === 'city0') {
        $index++;
        continue;
    }

This code does not help Also in the end of generating i got this

      'city1086' => [
            'name' => 'Яхрома',
            'latitude' => '56.2889858',
            'longitude' => '37.4831016',
        ],
    ],
    'city1' => [
        'city1' => [
            'name' => 'Абакан',
            'latitude' => '53.7223661',
            'longitude' => '91.4437792',
        ],

so i need to remove the second part that starts

'city1' => [

I wrote all the code, but can not remove this code

'city0' => [ 

from the fixture output, also when i generated city list once, then i got second generated part after i got item with [0][1086] index.

0

There are 0 best solutions below