PHP code example of farzai / php-types-guesser

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

    

farzai / php-types-guesser example snippets


use Farzai\Guesser\TypeGuesser;

$guesser = TypeGuesser::of("This is message");

// Print "This is message"
echo $guesser;

$guesser->isString() === true;

use Farzai\Guesser\TypeGuesser;

$guesser = TypeGuesser::of([1, 2]);

 // Print "[1, 2]"
echo $guesser;

$guesser->isArray() === true;
$guesser->isJson() === false;

use Farzai\Guesser\TypeGuesser;

$guesser = TypeGuesser::of("[1, 2]");

echo $guesser; // Print "[1, 2]"

$guesser->isArray() === true;
$guesser->isJson() === true;
$guesser->isString() === true;

use Farzai\Guesser\TypeGuesser;

// Try to enter string value
$guesser = TypeGuesser::of("true");
$guesser->isBoolean() === true;
$guesser->getValue() === true;

// Boolean type
$guesser = TypeGuesser::of(true);
$guesser->isBoolean() === true;
$guesser->getValue() === true;

use Farzai\Guesser\TypeGuesser;

$guesser = TypeGuesser::of("1");
$guesser->isNumeric() === true;
$guesser->isInteger() === true;
$guesser->isFloat() === false;
$guesser->getValue() === 1;


$guesser = TypeGuesser::of(1.2);
$guesser->isNumeric() === true;
$guesser->isInteger() === false;
$guesser->isFloat() === true;
$guesser->getValue() === 1.2;


$guesser = TypeGuesser::of("2.1");
$guesser->isNumeric() === true;
$guesser->isInteger() === false;
$guesser->isFloat() === true;
$guesser->getValue() === 2.1;
json
{
  "php": "^7.3||^8.0"
}

composer