PHP code example of p1ratrulezzz / lazyaccess

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

    

p1ratrulezzz / lazyaccess example snippets


isset($var) ? $var : NULL.



$somevar = isset($array[$key]['key2'][0]) ? $array[$key]['key2'][0] : 'some_default_value';
  
$wrapper = new LazyAccessTyped($array); //Define it once somewhere in your code
$somevar = $array[$key]->key2[0]->value('some_default_value');
//or
$somevar = $array[$key]['key2'][0]->value('some_default_value'); //the same as the above
//or
$somevar = $array->$key->key2->0->value('some_default_value'); //the same as the above
// Also there are some wrappers with types: asString(), asInteger(), asDouble()
$somevar = $array->{$key}->key2->0->asString('some_default_value');
$somevar = $array->{$key}->key2->0->asInteger(0); // It will perform intval() operation before returning, so you can be sure that there will be an integer value.
// asDouble() also will replace comma "," to a point ".", for example value 1,93 will be converted to 1.93
$floating_point_value = new LazyAccessTyped(['test_float' => ['inner' => '1,93']])->test_float->inner->asDouble(0); // Will return 1.93