PHP code example of andrew-gos / helpers

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

    

andrew-gos / helpers example snippets


use AndrewGos\Helpers\HArray;

$data = [
    ['city' => 'New York', 'role' => 'admin', 'name' => 'Alice'],
    ['city' => 'New York', 'role' => 'user', 'name' => 'Bob'],
    ['city' => 'London', 'role' => 'admin', 'name' => 'Charlie'],
];

// Group by city, then by role, and index elements by name
$result = HArray::groupExtended(
    array: $data,
    key: ['city', 'role'],
    index: 'name'
);

/* Output:
[
    'New York' => [
        'admin' => ['Alice' => [...]],
        'user'  => ['Bob' => [...]],
    ],
    'London' => [
        'admin' => ['Charlie' => [...]],
    ]
]
*/

use AndrewGos\Helpers\HArray;

$input = [1, [2, null, [3]], null];

// Recursively remove null values and "prune" empty branches
$filtered = HArray::filterRecursive($input, fn($v) => $v !== null);
// Output: [1, [2, [3]]]

use AndrewGos\Helpers\HString;

echo HString::rusToEng('Привет мир'); // Output: Privet mir
echo HString::changeEngKeyboardLayoutToRus('ghbdtn'); // Output: привет

use AndrewGos\Helpers\HString;

$data = ['id' => 1, 'active' => true, 'tags' => ['php', '8.4']];
echo HString::stringifyValue($data); 
// Output: [id => 1, active => true, tags => [0 => "php", 1 => "8.4"]]