PHP code example of tourze / gb-t-4762

1. Go to this page and download the library: Download tourze/gb-t-4762 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/ */

    

tourze / gb-t-4762 example snippets




use Tourze\GBT4762\PoliticalAffiliation;

// Get code value
$code = PoliticalAffiliation::CPC_MEMBER->value; // '01'

// Get label
$label = PoliticalAffiliation::CPC_MEMBER->getLabel(); // '中国共产党党员'

// Get all options for select components
$options = PoliticalAffiliation::genOptions();
// [{"label":"中国共产党党员","value":"01"}, ...]

// Convert to array format
$item = PoliticalAffiliation::CPC_MEMBER->toArray();
// ["value" => "01", "label" => "中国共产党党员"]

// Get select item format
$selectItem = PoliticalAffiliation::CPC_MEMBER->toSelectItem();
// ["label":"中国共产党党员","text":"中国共产党党员","value":"01","name":"中国共产党党员"]

// Create from value
$affiliation = PoliticalAffiliation::from('01'); // PoliticalAffiliation::CPC_MEMBER

// Try create from value (returns null if not found)
$affiliation = PoliticalAffiliation::tryFrom('99'); // null

// Hide the "群众" option from genOptions()
$_ENV['enum-display:Tourze\GBT4762\PoliticalAffiliation-13'] = false;

$options = PoliticalAffiliation::genOptions();
// The "群众" option will be excluded from the result