Below Code inserting City data twice. when i check for last insert id city data will duplicate is it a bug???

<?php

namespace Shopping\Controllers;

use Shopping\Models\Globcities; use Shopping\Models\Globpincodes;

class IndexController extends ControllerBase {

public function indexAction()
{
    include $this->config->application->libraryDir . 'simple_html_dom.php';
    $url = 'https://www.mapsofindia.com/pincode/india/karnataka/';

    $x = 'bangalore';
    $x = explode('|', $x);
    foreach ($x as $a) {
        $a = trim(preg_replace('%/$%', '', $a));
        $city = new Globcities();
        $city->city_name = $a;
        $city->city_state_id = 17;
        if ($city->create()) {
            //City Last Insert ID
            $city_id = $city->city_id;
            $html = file_get_html($url . $a);
            $pincodes = array();
            foreach ($html->find('.table_hide tr') as $k => $element) {
                if ($k == 0) continue;
                $Pin = (int)(trim($element->children(1)->plaintext));
                $pincodes[$Pin] = $Pin;
            }
            foreach ($pincodes as $p) {
                $pincode = new Globpincodes();
                $pincode->pincode_city_id = $city_id;
                $pincode->pincode_number = $p;
                $pincode->create();
            }
        }
     }
}

}