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 SbWereWolf\LanguageSpecific\AdvancedArray;
$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 AdvancedArray($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 SbWereWolf\LanguageSpecific\AdvancedArray;
$data = new AdvancedArray([0=>1]);
$data->has(); // true
// array has at least one element
$data = new AdvancedArray([0=>1]);
$data->has(0); // true
// array has element with index 0
$data = new AdvancedArray([2=>3]);
$data->has('4'); // false
// array not has element with index '4'
use SbWereWolf\LanguageSpecific\AdvancedArray;
$data = new AdvancedArray('1.1');
$data->get()->asIs(); // "1.1"
use SbWereWolf\LanguageSpecific\AdvancedArray;
$data = new AdvancedArray('1.1');
$data->get()->int(); // 1
use SbWereWolf\LanguageSpecific\AdvancedArray;
$data = new AdvancedArray('1.1');
$data->get()->double(); // 1.1
use SbWereWolf\LanguageSpecific\AdvancedArray;
$data = new AdvancedArray('1.1');
$data->get()->str(); // "1.1"
use SbWereWolf\LanguageSpecific\AdvancedArray;
$data = new AdvancedArray('1.1');
$data->get()->bool(); // true
use SbWereWolf\LanguageSpecific\AdvancedArray;
/* Let input string */
$data = new AdvancedArray('1.1');
$data->get()->array(); // [0 => "1.1"]
/* Let input array with string */
$data = new AdvancedArray(['1.1']);
$data->get()->array(); // [0 => "1.1"]
use SbWereWolf\LanguageSpecific\AdvancedArray;
use SbWereWolf\LanguageSpecific\Value\CommonValue;
$data = new AdvancedArray([new CommonValue()]);
$value = $data->get()->object();
var_export($value);
/*
\SbWereWolf\LanguageSpecific\Value\CommonValue::__set_state(array(
'_value' => NULL,
'_isReal' => true,
'_default' => NULL,
))
*/
use SbWereWolf\LanguageSpecific\AdvancedArray;
$data = new AdvancedArray([0=>1]);
$data->get(0)->isReal(); // true
// array element with index 0 has value
$data = new AdvancedArray([2=>3]);
$data->get('4')->isReal(); // false
// array do not have element with index '4' then value is not real
use SbWereWolf\LanguageSpecific\Value\CommonValue;
(new CommonValue(null))->type(); // `NULL`
(new CommonValue(false))->type(); // `boolean`
(new CommonValue(0))->type(); // `integer`
(new CommonValue(0.0))->type(); // `double`
(new CommonValue('a'))->type(); // `string`
(new CommonValue([]))->type(); // `array`
(new CommonValue(new CommonValue()))->type(); // `object`