PHP code example of napryc / php8-compat

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

    

napryc / php8-compat example snippets


use Napryc\PHP8Compat\PHP8Compat;

// String manipulation
$padded = PHP8Compat::mb_str_pad("Hello", 10, "-"); // "Hello-----"
$contains = PHP8Compat::str_contains("Hello World", "World"); // true
$starts = PHP8Compat::str_starts_with("Hello World", "Hello"); // true
$ends = PHP8Compat::str_ends_with("Hello World", "World"); // true

// String increment/decrement
$next = PHP8Compat::str_increment("a"); // "b"
$prev = PHP8Compat::str_decrement("b"); // "a"

// Multi-byte string functions
$trimmed = PHP8Compat::mb_trim("  Hello  "); // "Hello"

// Array checking
$isList = PHP8Compat::array_is_list([1, 2, 3]); // true

// Array searching
$found = PHP8Compat::array_find([1, 2, 3], fn($x) => $x > 1); // 2
$foundKey = PHP8Compat::array_find_key([1, 2, 3], fn($x) => $x > 1); // 1
$hasAny = PHP8Compat::array_any([1, 2, 3], fn($x) => $x > 2); // true
$allMatch = PHP8Compat::array_all([1, 2, 3], fn($x) => $x > 0); // true

// Safe division
$result = PHP8Compat::fdiv(10, 0); // INF