2017 © Pedro Peláez
 

library isget

This is a handy little helper function that is used to replace the common pattern of isset($a, $a['b']) ? $a['b'] : $c; which can be ugly and redundant.

image

artbit/isget

This is a handy little helper function that is used to replace the common pattern of isset($a, $a['b']) ? $a['b'] : $c; which can be ugly and redundant.

  • Wednesday, February 22, 2017
  • by ArtBIT
  • Repository
  • 0 Watchers
  • 1 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 37 % Grown

The README.md

isget() for PHP

Build Status GitHub license GitHub issues, (*1)

This is a handy little helper function that is used to replace the common pattern of isset($a, $a['b']) ? $a['b'] : $c; which can be ugly and redundant., (*2)

You can think of it as a long lost brother of isset()., (*3)

It does two things: * It silences down the PHP Undefined index notice, when trying to access an inexistent key in an array * And returns a default value if the key is not set, (*4)

Usage

``` php mixed isget(array $inputarray['somekey'], mixed $default_value), (*5)


If the `somekey` key is set, the function will return its value, if it's not, it will return the provided default value (or `false` by default); It comes in really handy, if your function supports an array of options, and you don't want to worry about checking if the option has been set or not. i.e. ``` php function do_something($required_param, $options = array()) { if (isget($options['forceint']) === true) { $required_param = intval($required_param); } if (isget($options['uppercase']) === true) { $required_param = strtoupper($required_param); } ... return $required_param; } $a = 12.34; echo do_something($a); // 12.34 echo do_something($a, array('forceint' => true)); // 12

If you need to go deeper, you can. ``` php $dream = array(); echo isget($dream['within_a_dream']['within_a_dream']['within_a_dream']['...'], 'inception!'); // inception!, (*6)


## Installation The easiest way to install this library is to use Composer and add the following to your project's `composer.json` file: ``` javascript { "require": { "artbit/isget": "dev-master" } }

Then, when you run composer install, everything will fall magically into place, and the isget() function will be available to your project, as long as you are including Composer's autoloader., (*7)

However, you do not need Composer to use this library., (*8)

This library has no dependencies and should work on older versions of PHP. Download the code and include src/isget.php in your project, and all should work fine., (*9)

The Versions

22/02 2017

dev-master

9999999-dev https://github.com/artbit/isget

This is a handy little helper function that is used to replace the common pattern of isset($a, $a['b']) ? $a['b'] : $c; which can be ugly and redundant.

  Sources   Download

MIT

helper array utility isset ternary

24/10 2015

v1.0.0

1.0.0.0 https://github.com/artbit/isget

This is a handy little helper function that is used to replace the common pattern of isset($a, $a['b']) ? $a['b'] : $c; which can be ugly and redundant.

  Sources   Download

MIT

helper array utility isset ternary

29/04 2014

v1.0

1.0.0.0 https://github.com/artbit/isget

This is a handy little helper function that is used to replace the common pattern of isset($a, $a['b']) ? $a['b'] : $c; which can be ugly and redundant.

  Sources   Download

MIT

helper array utility isset ternary