PHP code example of kevinpurwito / php-constant

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

    

kevinpurwito / php-constant example snippets


use KevinPurwito\PhpConstant\PhpConstant;

// Class Extends PhpConstant to use its functions
class StatusConst extends PhpConstant
{
    const PENDING = 'pending';
    const IN_PROCESS = 'in_process';
    const COMPLETED = 'completed';
}

/*
|--------------------------------------------------------------------------
| Framework Agnostic Functions
|--------------------------------------------------------------------------
|
| Simple functions not dependent to any framework and can be used in any PHP project.
|
*/

// returns an array like this: ['pending', 'in_process', 'completed']
StatusConst::all();

// returns a key-value array like this: ['pending' => 'Pending', 'in_process' => 'In Process', 'completed' => 'Completed']
StatusConst::options();

// returns a string like this: 'pending,in_process,completed'
StatusConst::asString();

// You can use any char you want as the glue for asString() function
// returns a string like this: 'pending|in_process|completed'
StatusConst::asString('|');

/*
|--------------------------------------------------------------------------
| Laravel Specific Functions
|--------------------------------------------------------------------------
|
| Functions to support [Laravel Collection](https://laravel.com/docs/collections) class.
| Laravel Collection is a class that provides a fluent, convenient wrapper for working with arrays of data.
|
*/

// returns a collection equivalent to: collect(['pending', 'in_process', 'completed'])
StatusConst::collect();

// returns a key-value collection equivalent to: collect(['pending' => 'Pending', 'in_process' => 'In Process', 'completed' => 'Completed'])
StatusConst::collectOptions();
bash
composer