PHP code example of timoreith / phpease

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

    

timoreith / phpease example snippets


use PhPease\ResultContainer;

$result = new ResultContainer();
$result->setSuccess(true)
       ->setMessage('Operation successful')
       ->setResult(['data' => 'value']);

if ($result->isSuccess()) {
    $result = $result->getResult();
} else {
    echo $result->getMessage();
}

use function PhPease\Variable\var_to_array;

// Example 1: Convert a string to an array
$string = "apple, banana, cherry";
$array = var_to_array($string);
print_r($array); // Output: ['apple', 'banana', 'cherry']

// Example 2: Convert a string to an array and apply a callback
$string = "1, 2, 3";
$array = var_to_array($string, 'intval');
print_r($array); // Output: [1, 2, 3]