PHP code example of kurianvarkey / helper-buddy

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

    

kurianvarkey / helper-buddy example snippets




use Net4ideas\HelperBuddy\JsonBuddy;

$keys = [
    "name" => "string:''",
    "structure.*.rows.*.columns.*.data" => "object",
    "structure.0.rows.0.columns.0.price" => "float:0",
];

$correctedJson = JsonBuddy::validateStructure($json, $keys);



use Net4ideas\HelperBuddy\ArrayBuddy;

$input = [
    "name" => "Jack",
    "age" => 40,
    "address" => null,
    "hobbies" => [
        "reading", 
        "writing", 
        null
    ]
];

$result = ArrayBuddy::removeNullValues($input);
/* Output:
[
    "name" => "Jack", 
    "age" => 40, 
    "hobbies" => [
        "reading", 
        "writing"
    ]
]
*/



use Net4ideas\HelperBuddy\ArrayBuddy;

$input = [
    "name" => "Jack",
    "age" => 40,
    "address" => null,
    "hobbies" => [
        "reading", 
        "writing", 
        null
    ]
];

$result = ArrayBuddy::replaceNullsWithString($input, 'default');
/* Output:
[
    "name" => "Jack",
    "age" => 40,
    "address" => "default",
    "hobbies" => [
        "reading", 
        "writing", 
        "default"
    ]
]
*/