Recommend this page to a friend! |
Download .zip |
Info | Example | View files (8) | Download .zip | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 218 | All time: 8,160 This week: 318 |
Version | License | PHP version | Categories | |||
php-arrays 1.0.0 | MIT/X Consortium ... | 5 | PHP 5, Data types |
Description | Author | ||||||||||||||
This class determine the type and run other array operations. Innovation Award |
|
A class to manipulate arrays in efficient ways to solve real world problems.
Installing this package is very simple, first ensure you have the right PHP version and composer installed then in your terminal/(command prompt) run:
composer require lablnet/arrays
1. Determine whether the given dataSet is really array?
- Example:
- ```php
use Lablnet\Arrays;
require '../vendor/autoload.php';
$arr = array(2, 2, 3, 4, 4, 4, 4, 8, 8, 6, 6, 9, 9, 9, 9);
var_dump(Arrays::isReallyArray($arr)); //True
var_dump(Arrays::isReallyArray([])); //False
```
2. Determine the given array is (sequential)indexes.?
- Example:
- ```php
use Lablnet\Arrays;
require '../vendor/autoload.php';
$arr = array(2, 2, 3, 4, 4, 4, 4, 8, 8, 6, 6, 9, 9, 9, 9);
var_dump(Arrays::isSequential($arr)); //True
var_dump(Arrays::isSequential(['a' => 1])); //False
```
3. Determine the given array is assoc.?
- Example:
- ```php
use Lablnet\Arrays;
require '../vendor/autoload.php';
$arr = array(2, 2, 3, 4, 4, 4, 4, 8, 8, 6, 6, 9, 9, 9, 9);
var_dump(Arrays::isAssoc($arr)); //False
var_dump(Arrays::isAssoc(['a' => 1])); //True
```
4. Determine the given array is multi-dimensional.?
- Example:
- ```php
use Lablnet\Arrays;
require '../vendor/autoload.php';
$arr = array(2, 2, 3, 4, 4, 4, 4, 8, 8, 6, 6, 9, 9, 9, 9);
var_dump(Arrays::isMulti($arr)); //False
var_dump(Arrays::isMulti(['a' => ['b' => 'c']])); //True
```
5. Get the type of array.
- Example:
- ```php
use Lablnet\Arrays;
require '../vendor/autoload.php';
$arr = array(2, 2, 3, 4, 4, 4, 4, 8, 8, 6, 6, 9, 9, 9, 9);
var_dump(Arrays::getType($arr)); //indexes
var_dump(Arrays::getType(['a' => ['b' => 'c']])); //multi
```
Add an element to an array using "operation" notation if it doesn't exist. - Example: - ```php use Lablnet\Arrays; require '../vendor/autoload.php'; var_dump(Arrays::add(['name' => 'desk', 'price' => null], 'price', 100)); // ['name' => 'desk', 'price' => 100] ```
7. Set an array item to a given value using "operator" notation. - Example: - ```php use Lablnet\Arrays; require '../vendor/autoload.php'; $array = ['products' => ['desk' => ['price' => 100]]]; Arrays::set($array, 'products.desk.price', 200, '.'); // ['products' => ['desk' => ['price' => 200]]] ```
Get an item from an array using "operator" notation(The `Arrays::get` method retrieves a value from a deeply nested array using "dot" notation:). - Example: - ```php use Lablnet\Arrays; require '../vendor/autoload.php'; $array = ['products' => ['desk' => ['price' => 100]]]; $price = Arrays::get($array, 'products.desk.price', '.'); // 100 ``` The `Arrays::get` method also accepts a default value, which will be returned if the specific key is not found.
9. Determine if an item or items exist in an array using 'Operator' notation.
- Example:
- ```php
use Lablnet\Arrays;
require '../vendor/autoload.php';
$array = ['product' => ['name' => 'Desk', 'price' => 100]];
$contains = Arrays::has($array, 'product.name', '.');
// true
$contains = Arrays::has($array, ['product.price', 'product.discount'], '.');
// false
Converted a multi-dimensional associative array with `dot`.
- Example:
- ```php
use Lablnet\Arrays;
require '../vendor/autoload.php';
$array = ['products' => ['desk' => ['price' => 100]]];
$dot= Arrays::dot($array);
// ['products.desk.price' => 100]
Push an item onto the beginning of an array.
- Example:
- ```php
use Lablnet\Arrays;
require '../vendor/autoload.php';
$array = ['red', 'green', 'blue'];
$prepend = Arrays::prepend($array, 'yellow');
// ['yellow', 'red', 'green', 'blue'];
Get the unique elements from arrays.
- Example:
- ```php
use Lablnet\Arrays;
require '../vendor/autoload.php';
$array = ['red', 'green', 'blue', 'red'];
$unique = Arrays::append($array);
// ['red', green', 'blue'];
Remove one or many array items from a given array using "operator" notation.
- Example:
- ```php
use Lablnet\Arrays;
require '../vendor/autoload.php';
$array = ['products' => ['desk' => ['price' => 100]]];
Arrays::forget($array, 'products.desk');
// ['products' => []]
Get a value from the array, and remove it.
- Example:
- ```php
use Lablnet\Arrays;
require '../vendor/autoload.php';
$array = ['name' => 'Desk', 'price' => 100];
$name = Arrays::pull($array, 'name');
// $array: ['price' => 100]
Files |
File | Role | Description | ||
---|---|---|---|---|
src (1 file) | ||||
Tests (1 file) | ||||
.travis.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpunit.xml | Data | Auxiliary data | ||
readme.md | Doc. | Documentation | ||
test.php | Example | Example script |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.