PHP code example of andrey-tech / utils-php

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

    

andrey-tech / utils-php example snippets


use \App\Utils\FileUtils;

class Example
{
    use FileUtils;

    public function __construct()
    {
        echo get_Name, $createDir = true);
        echo $absFileName . PHP_EOL;
    }
}

$e = new Example();

use \App\Utils\JsonUtils;

class Example
{
    use JsonUtils;

    public function __construct()
    {
        $data = [
            'array' => [ 0 => 0, 1 => 1, 2 => 2, 3 => 3 ],
            'object' => [ 'a' => '1', 'b' => 2, 'c' => 3 ],
        ];

        $json1 = $this->toJson($data, $encodeOptions = JSON_PRETTY_PRINT|JSON_PARTIAL_OUTPUT_ON_ERROR);
        echo $json1. PHP_EOL;

        $json2= $this->toJson($data, $encodeOptions = [ JSON_PRETTY_PRINT, JSON_FORCE_OBJECT ]);
        echo $json2. PHP_EOL;

        $data1 = $this->fromJson($json1);
        print_r($data1);

        $data2 = $this->fromJson($json2, $assoc = false);
        print_r($data2);
    }
}

$e = new Example();

use \App\Utils\Utils;

class Example
{
    use Utils;

    public function __construct()
    {
        $data1 = [ 0 => 0, 1 => 1, 2 => 2, 3 => 3 ];
        var_dump($this->isNumericArray($data1));

        $data2 = [ 'a' => '1', 'b' => 2, 'c' => 3 ];
        var_dump($this->isNumericArray($data2));
    }
}

$e = new Example();

$ composer 

"andrey-tech/utils-php"