• R/O
  • SSH
  • HTTPS

jinrousiki: Commit


Commit MetaInfo

Revision2321 (tree)
Time2019-01-21 21:09:16
Authorumethyl

Log Message

ArrayFilter::IsKey()

Change Summary

Incremental Difference

--- trunk/include/functions.php (revision 2320)
+++ trunk/include/functions.php (revision 2321)
@@ -417,12 +417,12 @@
417417 /* 取得 */
418418 //取得
419419 public static function Get(array $list, $key) {
420- return isset($list[$key]) ? $list[$key] : null;
420+ return self::IsKey($list, $key) ? $list[$key] : null;
421421 }
422422
423423 //取得 (int 型)
424424 public static function GetInt(array $list, $key) {
425- return isset($list[$key]) ? intval($list[$key]) : 0;
425+ return (int) self::Get($list, $key);
426426 }
427427
428428 //取得 (配列型)
@@ -466,14 +466,19 @@
466466 }
467467
468468 /* 判定 */
469+ //配列添字
470+ public static function IsKey(array $list, $key) {
471+ return isset($list[$key]);
472+ }
473+
469474 //連想配列
470475 public static function IsAssoc(array $list, $key) {
471- return isset($list[$key]) && is_array($list[$key]);
476+ return self::IsKey($list, $key) && is_array($list[$key]);
472477 }
473478
474479 //存在 (key ベース)
475480 public static function Exists($data, $key) {
476- return is_array($data) && isset($data[$key]);
481+ return is_array($data) && self::IsKey($data, $key);
477482 }
478483
479484 //存在 (is_array() && in_array() ラッパー)
@@ -483,7 +488,7 @@
483488
484489 //存在 (連想配列内 key)
485490 public static function IsIncludeKey(array $list, $key, $value) {
486- return isset($list[$key]) && array_key_exists($value, $list[$key]);
491+ return self::IsKey($list, $key) && array_key_exists($value, $list[$key]);
487492 }
488493
489494 /* 変換 */
@@ -526,12 +531,14 @@
526531 //初期化
527532 public static function Initialize(array &$list, $target, $value = []) {
528533 if (is_array($target)) {
529- foreach ($target as $key) self::Initialize($list, $key);
534+ foreach ($target as $key) {
535+ self::Initialize($list, $key);
536+ }
530537 } else {
531538 $key = $target;
532539 }
533540
534- if (! self::IsAssoc($list, $key)) {
541+ if (false === self::IsAssoc($list, $key)) {
535542 $list[$key] = $value;
536543 }
537544 }
@@ -539,7 +546,9 @@
539546 //空配列化
540547 public static function Reset(array &$list, $target) {
541548 if (is_array($target)) {
542- foreach ($target as $key) self::Reset($list, $key);
549+ foreach ($target as $key) {
550+ self::Reset($list, $key);
551+ }
543552 } else {
544553 $key = $target;
545554 }
@@ -548,7 +557,7 @@
548557
549558 //追加
550559 public static function Add(array &$list, $key, $value = 1) {
551- if (isset($list[$key])) {
560+ if (self::IsKey($list, $key)) {
552561 $list[$key] += $value;
553562 } else {
554563 $list[$key] = $value;
@@ -557,7 +566,7 @@
557566
558567 //登録
559568 public static function Register(array &$list, $value) {
560- if (! in_array($value, $list)) {
569+ if (false === in_array($value, $list)) {
561570 $list[] = $value;
562571 }
563572 }
@@ -564,8 +573,8 @@
564573
565574 //bool 反転
566575 public static function ReverseBool(array &$list, $key) {
567- if (isset($list[$key])) {
568- $list[$key] = ! $list[$key];
576+ if (self::IsKey($list, $key)) {
577+ $list[$key] = (false === $list[$key]);
569578 } else {
570579 $list[$key] = true;
571580 }
@@ -587,9 +596,12 @@
587596 //削除
588597 public static function Delete(array &$list, $value) {
589598 $key = array_search($value, $list);
590- if (false === $key) return false;
591- unset($list[$key]);
592- return true;
599+ if (false === $key) {
600+ return false;
601+ } else {
602+ unset($list[$key]);
603+ return true;
604+ }
593605 }
594606
595607 //切り詰め (削除 + 再生成)
Show on old repository browser