ArrayFilter::IsKey()
@@ -417,12 +417,12 @@ | ||
417 | 417 | /* 取得 */ |
418 | 418 | //取得 |
419 | 419 | public static function Get(array $list, $key) { |
420 | - return isset($list[$key]) ? $list[$key] : null; | |
420 | + return self::IsKey($list, $key) ? $list[$key] : null; | |
421 | 421 | } |
422 | 422 | |
423 | 423 | //取得 (int 型) |
424 | 424 | public static function GetInt(array $list, $key) { |
425 | - return isset($list[$key]) ? intval($list[$key]) : 0; | |
425 | + return (int) self::Get($list, $key); | |
426 | 426 | } |
427 | 427 | |
428 | 428 | //取得 (配列型) |
@@ -466,14 +466,19 @@ | ||
466 | 466 | } |
467 | 467 | |
468 | 468 | /* 判定 */ |
469 | + //配列添字 | |
470 | + public static function IsKey(array $list, $key) { | |
471 | + return isset($list[$key]); | |
472 | + } | |
473 | + | |
469 | 474 | //連想配列 |
470 | 475 | 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]); | |
472 | 477 | } |
473 | 478 | |
474 | 479 | //存在 (key ベース) |
475 | 480 | public static function Exists($data, $key) { |
476 | - return is_array($data) && isset($data[$key]); | |
481 | + return is_array($data) && self::IsKey($data, $key); | |
477 | 482 | } |
478 | 483 | |
479 | 484 | //存在 (is_array() && in_array() ラッパー) |
@@ -483,7 +488,7 @@ | ||
483 | 488 | |
484 | 489 | //存在 (連想配列内 key) |
485 | 490 | 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]); | |
487 | 492 | } |
488 | 493 | |
489 | 494 | /* 変換 */ |
@@ -526,12 +531,14 @@ | ||
526 | 531 | //初期化 |
527 | 532 | public static function Initialize(array &$list, $target, $value = []) { |
528 | 533 | if (is_array($target)) { |
529 | - foreach ($target as $key) self::Initialize($list, $key); | |
534 | + foreach ($target as $key) { | |
535 | + self::Initialize($list, $key); | |
536 | + } | |
530 | 537 | } else { |
531 | 538 | $key = $target; |
532 | 539 | } |
533 | 540 | |
534 | - if (! self::IsAssoc($list, $key)) { | |
541 | + if (false === self::IsAssoc($list, $key)) { | |
535 | 542 | $list[$key] = $value; |
536 | 543 | } |
537 | 544 | } |
@@ -539,7 +546,9 @@ | ||
539 | 546 | //空配列化 |
540 | 547 | public static function Reset(array &$list, $target) { |
541 | 548 | if (is_array($target)) { |
542 | - foreach ($target as $key) self::Reset($list, $key); | |
549 | + foreach ($target as $key) { | |
550 | + self::Reset($list, $key); | |
551 | + } | |
543 | 552 | } else { |
544 | 553 | $key = $target; |
545 | 554 | } |
@@ -548,7 +557,7 @@ | ||
548 | 557 | |
549 | 558 | //追加 |
550 | 559 | public static function Add(array &$list, $key, $value = 1) { |
551 | - if (isset($list[$key])) { | |
560 | + if (self::IsKey($list, $key)) { | |
552 | 561 | $list[$key] += $value; |
553 | 562 | } else { |
554 | 563 | $list[$key] = $value; |
@@ -557,7 +566,7 @@ | ||
557 | 566 | |
558 | 567 | //登録 |
559 | 568 | public static function Register(array &$list, $value) { |
560 | - if (! in_array($value, $list)) { | |
569 | + if (false === in_array($value, $list)) { | |
561 | 570 | $list[] = $value; |
562 | 571 | } |
563 | 572 | } |
@@ -564,8 +573,8 @@ | ||
564 | 573 | |
565 | 574 | //bool 反転 |
566 | 575 | 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]); | |
569 | 578 | } else { |
570 | 579 | $list[$key] = true; |
571 | 580 | } |
@@ -587,9 +596,12 @@ | ||
587 | 596 | //削除 |
588 | 597 | public static function Delete(array &$list, $value) { |
589 | 598 | $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 | + } | |
593 | 605 | } |
594 | 606 | |
595 | 607 | //切り詰め (削除 + 再生成) |