1. Go to this page and download the library: Download duzun/array 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/ */
duzun / array example snippets
use duzun\ArrayClass as AC;
ArrayClass::to_array($object, $recursive=false)
AC::to_array(1); // [1]
AC::to_array((function() { yield 1; })()); // [1]
AC::to_array(new \ArrayObject([1,2,3])); // [1,2,3]
AC::to_array($o = new class {}); // $o - don't know how to convert :(
$array = [1, 2, 3, 4, ..., 1000];
// get a sample of 10% of $array
AC::sample([$arr], 0.10) == [1, 10, 20, ..., 990, 1000];
// get a sample of 3 element of $array
AC::sample([$arr], 3) == [1, 500, 1000];
// validate the array has only (int)s, with some probability
AC::sample([$arr], 0.25, function ($v) { return is_int($v); }) == true;
// get the types of the array elements with proportion
AC::sample(
[0, 1.0, 'a', true, null, [], $this],
0.999,
function ($v) { return gettype($v); }
) == [
'integer' => 0.14285714285714285,
'double' => 0.14285714285714285,
'string' => 0.14285714285714285,
'boolean' => 0.14285714285714285,
'NULL' => 0.14285714285714285,
'array' => 0.14285714285714285,
'object' => 0.14285714285714285,
];
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.