PHP code example of jasny / php-functions

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

    

jasny / php-functions example snippets


$found = str_contains($string, 'foo') && array_contains($array, ['all', 'of', 'these']);
// VS
$found = strpos($string, 'foo') !== false && count(array_intersect($array, ['all', 'of', 'these'])) === 3;

use function Jasny\str_contains; // Import functions

str_contains('moonrise', 'on');

Jasny\slug('Foo bár'); // or use directly



expect_type($input, ['array', 'stdClass']);
expect_type($output, ['array', 'stdClass'], 'UnexpectedValueException', "Output should be an array or stdClass object, got a %s");

$values = array_flatten('.', [
    'animal' => [
        'mammel' => [
            'ape',
            'bear'
        ],
        'reptile' => 'chameleon'
    ],
    'colors' => [
        'red' => 60,
        'green' => 100,
        'blue' => 0
    ]
]);

[
    'animal.mammel' => [
        'ape',
        'bear'
    ],
    'animal.reptile' => 'chameleon',
    'colors.red' => 60,
    'colors.green' => 100,
    'colors.blue' => 0
]

echo "A task to " . array_join_pretty(", ", " and ", $chores) . " has been created.", PHP_EOL;
echo array_join_pretty(", ", " or ", $names) . " may pick up this task.", PHP_EOL;

"autoload": {
    "files": [
        "vendor/jasny/php-functions/global.php"
    ]
}