PHP code example of parsilver / thailand-provinces-php
1. Go to this page and download the library: Download parsilver/thailand-provinces-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
parsilver / thailand-provinces-php example snippets
use PA\ProvinceTh\Factory;
$provinces = Factory::province(); // PA\ProvinceTh\Provider\ProviderCollection
echo $provinces; // Json
$provinceArray = $provinces->toArray();
$amphures = $provinces->find(1)->amphures(); // PA\ProvinceTh\Provider\ProviderCollection
echo $amphures; // Json
use PA\ProvinceTh\Factory;
/**
* ภูมิภาค
* @return PA\ProvinceTh\Provider\Geography|PA\ProvinceTh\Provider\ProviderCollection
*/
$geography = Factory::geography();
/**
* จังหวัด
* @return PA\ProvinceTh\Provider\Province|PA\ProvinceTh\Provider\ProviderCollection
*/
$provinces = Factory::province();
/**
* อำเภอ
* @return PA\ProvinceTh\Provider\Amphure|PA\ProvinceTh\Provider\ProviderCollection
*/
$amphures = Factory::amphure();
/**
* ตำบล
* @return PA\ProvinceTh\Provider\District|PA\ProvinceTh\Provider\ProviderCollection
*/
$districts = Factory::district();
use PA\ProvinceTh\Factory;
/**
* @return PA\ProvinceTh\Provider\ProviderCollection
*/
$provinces = Factory::province();
/**
* จำนวน
* @return int
*/
$provinces->count();
/**
* ค้นหาจาก Primary key และ return 1 column
* @return PA\ProvinceTh\Provider\ProviderCollection
*/
$provinces->find($id);
/**
* ค้นหา
* @return PA\ProvinceTh\Provider\ProviderCollection
*/
$provinces->where($key, $value);
/**
* Foreach
*@return Void
*/
$provinces->each(function($value, $key){
// หาต้องการหยุด ให้ return false
});
/**
* ค้นหาด้วยตัวเอง
* @return PA\ProvinceTh\Provider\ProviderCollection
*/
$provinces->filter(function($value, $key){
return true; // Return true หากค้นพบ
});
/**
* @return array
*/
$provinces->toArray();
/**
* Get primary key
* @return string
*/
$provinces->getPrimaryKey()
use PA\ProvinceTh\Factory;
$geography = Factory::geography();
/**
* จังหวัดของภูมิภาคนั้น
* @return PA\ProvinceTh\Provider\Province|PA\ProvinceTh\Provider\ProviderCollection
*/
$geography->find(1)->provinces();
use PA\ProvinceTh\Factory;
$province = Factory::province();
/**
* ภูมิภาคของจังหวัดนั้น
* @return PA\ProvinceTh\Provider\Geography|PA\ProvinceTh\Provider\ProviderCollection
*/
$province->find(1)->geography();
/**
* อำเภอทั้งหมดคของจังหวัดนั้น
* @return PA\ProvinceTh\Provider\Amphure|PA\ProvinceTh\Provider\ProviderCollection
*/
$province->find(1)->amphures();
use PA\ProvinceTh\Factory;
$amphure = Factory::amphure();
/**
* จังหวัดคของอำเภอนั้น
* @return PA\ProvinceTh\Provider\Province|PA\ProvinceTh\Provider\ProviderCollection
*/
$amphure->find(1)->province();
/**
* ตำบลทั้งหมดของอำเภอนั้น
* @return PA\ProvinceTh\Provider\District|PA\ProvinceTh\Provider\ProviderCollection
*/
$amphure->find(1)->districts();
use PA\ProvinceTh\Factory;
$district = Factory::district();
/**
* อำเภอของตำบลนั้น
* @return PA\ProvinceTh\Provider\Amphure|PA\ProvinceTh\Provider\ProviderCollection
*/
$district->find(1)->amphure();
{
"php" : "^7.3||^8.0",
}