appzz/arr

A safe way to get values from arrays

1.0.4 2017-05-07 21:19 UTC

This package is auto-updated.

Last update: 2024-12-18 02:44:50 UTC


README

Simple and safest way to get values from arrays.

Example:

#!php

use \AppZz\Helpers\Arr as Arr;
$arr = [
	'foo' => '123',
	'bar' => '456',
	'qwe' => [
		'a'=>'ert',
		'b'=>'asd',
		'c'=>[
			'aa'=>2,
			'bb'=>3
		]
	]
];

var_dump(Arr::get($arr, 'foo'));
var_dump(Arr::get($arr, 'foo1'));
var_dump(Arr::get($arr, 'foo1', 3));
var_dump(Arr::get($arr, 'bar'));
var_dump(Arr::path($arr, 'qwe.a'));
var_dump(Arr::path($arr, 'qwe.b'));
var_dump(Arr::path($arr, 'qwe.aa'));
var_dump(Arr::path($arr, 'qwe.c.aa'));
var_dump(Arr::path($arr, 'qwe#c#aa', '#'));
var_dump(Arr::path($arr, 'qwe#c#aaa', '#', 22));