PHP code example of sbwerewolf / language-specific
1. Go to this page and download the library: Download sbwerewolf/language-specific 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/ */
sbwerewolf / language-specific example snippets
array_key_exists()
intval()
boolval()
floatval()
and others
use LanguageSpecific\ArrayHandler;
$connection = new PDO ($dsn,$login,$password);
$command = $connection->
prepare('select name,salary from employee'
. ' ORDER BY salary DESC LIMIT 1');
$command->execute();
$data = $command->fetch(PDO::FETCH_ASSOC);
/*
$data =
array (
'name' => 'Mike',
'salary'=> 19999.99
);
*/
$employee = new ArrayHandler($data);
echo "The highest paid employee is {$employee->get('name')->str()}"
. ", with salary of {$employee->get('salary')->int()}$";
/*
The highest paid employee is Mike, with salary of 19999$
*/
use LanguageSpecific\ArrayHandler;
$data = new ArrayHandler([0=>1]);
$data->has(); // true
// array has at least one index (element)
$data = new ArrayHandler([0=>1]);
$data->has(0); // true
// array has index 0
$data = new ArrayHandler([2=>3]);
$data->has('4'); // false
// array not has index '4'
use LanguageSpecific\ArrayHandler;
$data = new ArrayHandler('1.1');
$data->get()->asIs(); // '1.1'
use LanguageSpecific\ArrayHandler;
$data = new ArrayHandler('1.1');
$data->get()->int(); // 1
use LanguageSpecific\ArrayHandler;
$data = new ArrayHandler('1.1');
$data->get()->double(); // 1.1
use LanguageSpecific\ArrayHandler;
$data = new ArrayHandler('1.1');
$data->get()->str(); // '1.1'
use LanguageSpecific\ArrayHandler;
$data = new ArrayHandler('1.1');
$data->get()->bool(); // true
use LanguageSpecific\ArrayHandler;
$data = new ArrayHandler([1.1]);
$data->get()->array(); // [1.1]
use LanguageSpecific\ArrayHandler;
use LanguageSpecific\ValueHandler;
$data = new ArrayHandler(new ValueHandler());
$value = $data->get()->object();
var_export($value,true);
/*
LanguageSpecific\ValueHandler::__set_state(array(
'_value' => NULL,
'_has' => true,
'_default' => NULL,
))
*/
use LanguageSpecific\ArrayHandler;
$data = new ArrayHandler([0=>1]);
$data->get(0)->has(); // true
// array element with index 0 has value
$data = new ArrayHandler([2=>3]);
$data->get('4')->has(); // false
// array element with index '4' not has value
use LanguageSpecific\ValueHandler;
(new ValueHandler(null))->type(); // `NULL`
(new ValueHandler(false))->type(); // `boolean`
(new ValueHandler(0))->type(); // `integer`
(new ValueHandler(0.0))->type(); // `double`
(new ValueHandler('a'))->type(); // `string`
(new ValueHandler([]))->type(); // `array`
(new ValueHandler(new ValueHandler()))->type(); // `object`
use LanguageSpecific\ValueHandler;
ValueHandler::asUndefined()->default('default')->str(); // 'default'
(new ValueHandler('string'))->default('default')->str(); // 'string'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.