PHP code example of slince / china

1. Go to this page and download the library: Download slince/china 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/ */

    

slince / china example snippets



$china = new China();

$holidayService = $chna->getHoliday();

print_r($holidayService->findAll());


$yuandan = $holidayService->find('元旦节'):
 
 echo $yuandan->getDate(); //输出 1月1日


$china = new China();

$nationalityService = $chna->getNationality();

print_r($nationalityService->findAll());


$hezhe = $nationalityService->find('赫哲族'):
 
 echo $hezhe->getPinyin(); //输出“hè zhé zú”
 echo $hezhe->getPopulation(); //输出人口


$china = new China();

$regionService = $china->getRegion();

print_r($regionService->getProvinces()); //获取树形省市县地区结构

$bengbushi = $regionService->findByName('蚌埠市');
echo $bengbushi->getParent()->getName(); //输出蚌埠市所属省, 安徽省

$huaiyuan = $regionService->findByIdCard('340321199212026972');

$yuhuiqu = $bengbushi->getChildren()->findByName('禹会区'); //蚌埠市下属禹会区
$yuhuiqu->getParent()->getChildren()->findByName('淮上区'); //禹会区同级淮上区

$bengbushi = $regionService->findByName('蚌埠市');
echo json_encode($bengbushi);

$bengbushi = $regionService->findByName('蚌埠市');
$bengbushi = clone $bengbushi; //此处需要克隆对象,如果直接修改会破坏原有的地区树结构
$bengbushi->setChildren([]);
echo json_encode($bengbushi);