PHP code example of miguelcalderonb / meta-statements

1. Go to this page and download the library: Download miguelcalderonb/meta-statements 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/ */

    

miguelcalderonb / meta-statements example snippets


use Miguelcalderonb\MTStatements\Conditionals\StmIfExec;

StmIfExec::run(10, '==', 10);
//Output: bool(true)

use Miguelcalderonb\MTStatements\Conditionals\StmIf;

$ifStatement = new StmIf(10, '==', 10);
$ifStatement->run(); 
//Output: bool(true)


use Miguelcalderonb\MTStatements\Conditionals\StmIfExec;

$customFunction = function ($result ) {
    if ($result) {
        return 'Allowed';
    }

    return 'Rejected';
};

StmIfExec::run(10, '==', 10, $customFunction);
//Output: Allowed

StmIfExec::run(10, '==', 20, $customFunction);
//Output: Rejected

use Miguelcalderonb\MTStatements\Conditionals\StmIf;

$customFunction = function ($result ) {
    if ($result) {
        return 'Allowed';
    }

    return 'Rejected';
};


$ifStatement = new StmIf(10, '==', 10, $customFunction);
$ifStatement->run(); //Output: Allowed

$ifStatement->second =  20;
$ifStatement->run();
//Output: Rejected


use Miguelcalderonb\MTStatements\Conditionals\StmIf;
use Miguelcalderonb\MTStatements\Structs\StatementIfList;
use Miguelcalderonb\MTStatements\Conditionals\StmIfMulti;

$value = 7;

$firstStm = new StmIf($value, '>=', 1, null, '&&');
$secondStm = new StmIf($value, '<=', 7, null);

$listStm = new StatementIfList();
$listStm->add($firstStm);
$listStm->add($secondStm);

$customFunction = function($result) {
    if ($result) {
        return 'Value between 1 and 7';
    }

    return 'Value is not between 1 and 7';
};

$stmMulti = new StmIfMulti($listStm, $customFunction);
$stmMulti->run();

//Output: Value between 1 and 7

use Miguelcalderonb\MTStatements\Structs\LoopRestriction;
use Miguelcalderonb\MTStatements\Loops\StmWhileExec;

$execInEachLoop = function($firstValue) {
    echo $firstValue."\n";
};

$restrict = new LoopRestriction('+', 'before', 1);
StmWhileExec::run(0, '<=', 10, $restrict, $execInEachLoop);

// Output
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// 10
// 11