This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ordutf8_step1(string $char) : int | |
{ | |
$code = ord(substr($char, 0, 1)); | |
if ($code >= 128) { | |
if ($code < 224) | |
$bytesnumber = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Return numerical part of the HTML encoding of the Unicode character. | |
* | |
* @param string $char | |
* @return int | |
*/ | |
function ordutf8(string $char) : int | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Parent class for custom model classes. | |
* | |
* This class was implemented like part of Observer pattern | |
* https://en.wikipedia.org/wiki/Observer_pattern | |
* http://php.net/manual/en/class.splsubject.php | |
*/ | |
class Model implements SplSubject { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert number given as string to the proper type (int or float). | |
* https://secure.php.net/manual/en/language.types.type-juggling.php | |
* | |
* @param string $string Number as string ex '1.0', '0.9' etc | |
* @return int|float | |
*/ | |
function strtonum(string $string) | |
{ | |
if (fmod((float)$string, 1.0) === 0.0){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check if value is between given range. | |
* | |
* @param mixed $value | |
* @param mixed $min | |
* @param mixed $max | |
* | |
* @return bool | |
*/ | |
function in_range($value, $min, $max): bool { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//change for point to correct directory | |
include '../linna-array/src/TypedArray.php'; | |
include '../linna-array/src/TypedObjectArray.php'; | |
use Linna\TypedArray; | |
use Linna\TypedObjectArray; | |
$cicles = 500000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get appropriate cost | |
* | |
* This code will benchmark your server to determine how high of a cost you can | |
* afford. You want to set the highest cost that you can without slowing down | |
* you server too much. | |
* | |
* @param int $time_limit Time limit in milliseconds | |
* @param int $algo Algoritm, default PASSWORD_DEFAULT | |
* @return int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Flatten an array | |
* Example array [1, [2, 3, 4], [5, 6], [7, [8, 9]], 10] becomes | |
* [1, 2, 3, 4, 5, 6, 7, [8, 9], 10] | |
* Work only for one level | |
* | |
* @param array $array Array to flatten | |
* @return array | |
*/ | |
function array_flatten(array $array): array |