PHPackages                             kristos80/opton - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. kristos80/opton

ActiveLibrary

kristos80/opton
===============

Easily get a value from an array or object without all of those unnecessary array\_key\_exists or isset controls

v1.1.2(6y ago)14.3k1MITPHPCI failing

Since Feb 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/kristos80/Opton)[ Packagist](https://packagist.org/packages/kristos80/opton)[ RSS](/packages/kristos80-opton/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (7)Used By (1)

[![Reliability Rating](https://camo.githubusercontent.com/a9b289624d6486ae1d37cdc72b476a2a7743c2f4a7516d37ab5bb5116e0e33da/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6b726973746f7338305f4f70746f6e266d65747269633d72656c696162696c6974795f726174696e67)](https://sonarcloud.io/dashboard?id=kristos80_Opton)[![Security Rating](https://camo.githubusercontent.com/93b4f95c9e73fb387ceaafeb27f8ce63c9f7248d350f6b3d7c24dd760f30bd4a/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6b726973746f7338305f4f70746f6e266d65747269633d73656375726974795f726174696e67)](https://sonarcloud.io/dashboard?id=kristos80_Opton)[![Technical Debt](https://camo.githubusercontent.com/5baa674ddd0c332574595d7cc5fdf950c6204c1f886ac3dd57a1933954389efe/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6b726973746f7338305f4f70746f6e266d65747269633d7371616c655f696e646578)](https://sonarcloud.io/dashboard?id=kristos80_Opton)[![Vulnerabilities](https://camo.githubusercontent.com/28251631b456b3a4d284972e1a1ae85b2076dcc5358b7b45bde6c0255a35a9fc/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6b726973746f7338305f4f70746f6e266d65747269633d76756c6e65726162696c6974696573)](https://sonarcloud.io/dashboard?id=kristos80_Opton)[![Bugs](https://camo.githubusercontent.com/3d2d3439c47d8d266ff1ae4ddcc64daec4bfeee168966a85ef204932d64df4b5/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6b726973746f7338305f4f70746f6e266d65747269633d62756773)](https://sonarcloud.io/dashboard?id=kristos80_Opton)[![Codacy Badge](https://camo.githubusercontent.com/a3d6c3e361dde6d53d09da114a14ff9f65433d960e25c2a6f582024ba693c3eb/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3364386231326463353138393435363838613464356138366631373937666338)](https://www.codacy.com/manual/kristos80/Opton?utm_source=github.com&utm_medium=referral&utm_content=kristos80/Opton&utm_campaign=Badge_Grade)[![Maintainability](https://camo.githubusercontent.com/b62446d551781f286b22d395194ab52d1561b8ee4e92fc75ba5ea65f2b5c0df7/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f62323730636537373830616238323262343131622f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/kristos80/Opton/maintainability)[![CodeScene Code Health](https://camo.githubusercontent.com/4a9e843f2544a8b3499b01ac4de2b4dae669840413a4c0d34563db2bd520b7e1/68747470733a2f2f636f64657363656e652e696f2f70726f6a656374732f363839342f7374617475732d6261646765732f636f64652d6865616c7468)](https://codescene.io/projects/6894)[![CodeScene System Mastery](https://camo.githubusercontent.com/4d0bc5483ecb17ebf14cbe47fe05fa3c97425844529687b0c91b2853bacd3d0c/68747470733a2f2f636f64657363656e652e696f2f70726f6a656374732f363839342f7374617475732d6261646765732f73797374656d2d6d617374657279)](https://codescene.io/projects/6894)[![Packagist](https://camo.githubusercontent.com/53f995f2ad025f99d79ba252482a36e3fb8171d43c69d15e2f249642b157fe74/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6b726973746f7338302f6f70746f6e)](https://camo.githubusercontent.com/53f995f2ad025f99d79ba252482a36e3fb8171d43c69d15e2f249642b157fe74/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6b726973746f7338302f6f70746f6e)

Opton
=====

[](#opton)

Easily get a value from an array or object without all of those unnecessary `array_key_exists` or `isset` controls.

Install (via composer)
----------------------

[](#install-via-composer)

```
$ composer require kristos80/opton

```

Notation syntax allowed as of version 1.1.2
-------------------------------------------

[](#notation-syntax-allowed-as-of-version-112)

```
$dataContainer = array(
	'container' => (object) array( // Object or array it doesn't matter
		'nested' => array(
			'value' => array(
				'in' => array(
					'value',
				),
			),
		),
	),
);

echo Opton::get('container.nested.value.in', $dataContainer); // Prints `value`
```

Source code
-----------

[](#source-code)

```
/**
 *
 * @param array|object|string $name
 *        	The name of the option/key to be found
 * @param array|object|NULL $pool
 *        	The pool of data to search within
 * @param mixed|NULL $default
 *        	Default value if nothing is found
 * @param array|object|NULL $acceptedValues
 *        	Array of accepted values. It affects even the `default` value
 * @return mixed|NULL
 */
static function get($name, $pool = array(), $default = NULL, array $acceptedValues = array()) {
```

Examples
--------

[](#examples)

```
