PHP code example of phdevutils / psgc-barangays

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

    

phdevutils / psgc-barangays example snippets


[
  'code' => '012801001',   // PSGC 9-digit
  'name' => 'Adams (Pob.)',
  'cityMunCode' => '012801',// 6-digit parent (joins phdevutils/core)
  'province' => '0128',     // 4-digit, or null for HUC/NCR
  'region' => '01',         // 2-digit
]

Barangays::list(['cityMunCode' => '012801']);
Barangays::list(['region' => '13']);     // all NCR
Barangays::list(['province' => null]);   // HUC/NCR with no province

Barangays::find('012801001'); // ['code' => '012801001', 'name' => 'Adams (Pob.)', ...]
Barangays::find('999999999'); // null

Barangays::findByName('San Isidro');                    // 296
Barangays::findByName('San Isidro', ['region' => '13']); // 3

Barangays::count();                   // 42046
Barangays::count(['region' => '13']); // 1710