artbit/isget 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

artbit/isget

Composer 安装命令:

composer require 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.

README 文档

README

Build Status GitHub license GitHub issues

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.

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

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

Usage

mixed isget(array $inputarray['somekey'], mixed $default_value)

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.

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.

$dream = array();
echo isget($dream['within_a_dream']['within_a_dream']['within_a_dream']['...'], 'inception!');
// inception!

Installation

The easiest way to install this library is to use Composer and add the following to your project's composer.json file:

{
    "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.

However, you do not need Composer to use this library.

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.

统计信息

  • 总下载量: 61
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固