PHP code example of greeny / array-class

1. Go to this page and download the library: Download greeny/array-class 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/ */

    

greeny / array-class example snippets


$array = [];
array_push($array, 0, 1, 2, 3);
shuffle($array);
$array = array_map(function ($item) {
	return $item * 2;
}, $array);
$array = array_filter($array);
print_r($array);

$array = ArrayClass::from([])
	->push(0, 1, 2, 3)
	->shuffle()
	->map(function ($item) {
		return $item * 2;
	})
	->filter()
	->toArray();
	
print_r($array);

$array = ArrayClass::from([]);

// you can count elements natively
count($array);

// iterate over elements
foreach ($array as $key => $value) {
	// do stuff
}

// and even modify some of them!
$array[1] = 4;
$array[2] = $array[3] * isset($array[4]) ? $array[4] : 4;
unset($array[5]);





// import class
use greeny\ArrayClass\ArrayClass; // yes, I know, weird namespace

$array = new ArrayClass; // initializes from empty array
$array = new ArrayClass($original); // initializes from original array
$array = ArrayClass::from($original); // same as before, good for chaining methods immidiatelly, like below:

$array = ArrayClass::from($original)->filter()->shuffle(); // etc etc