PHP code example of ntzm / strict-casts
1. Go to this page and download the library: Download ntzm/strict-casts 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/ */
ntzm / strict-casts example snippets
(int) 'hello' === 0;
(int) '5 hello' === 5;
(int) 'hello 5' === 0;
(int) '123,456' === 123;
use function StrictCasts\stringToInt;
stringToInt('123') === 123;
stringToInt('-123') === -123;
stringToInt('hello'); // throws exception
stringToInt('5 hello'); // throws exception
stringToInt('hello 5'); // throws exception
stringToInt('123,456'); // throws exception