coderius/php-helpers

Provides php helpers.

v0.0.2 2023-04-01 20:10 UTC

This package is auto-updated.

Last update: 2024-10-30 02:16:21 UTC


README

  • ArrayHelper

ArrayHelper usage:

  • ArrayHelper::toArray($object, $properties = [], $recursive = true)
  • ArrayHelper::merge($ar, $ar2)
  • ArrayHelper::getValue($array, $key, $default = null)
  • ArrayHelper::setValue(&$array, $path, $value)
  • ArrayHelper::remove(&$array, $key, $default = null)
  • ArrayHelper::removeValue(&$array, $value)
  • ArrayHelper::index($array, $key, $groups = [])
  • ArrayHelper::getColumn($array, $name, $keepKeys = true)
  • ArrayHelper::map($array, $from, $to, $group = null)
  • ArrayHelper::keyExists($key, $array, $caseSensitive = true)
  • ArrayHelper::multisort(&$array, $key, $direction = SORT_ASC, $sortFlag = SORT_REGULAR)
  • ArrayHelper::htmlEncode($data, $valuesOnly = true, $charset = null)
  • ArrayHelper::htmlDecode($data, $valuesOnly = true)
  • ArrayHelper::isAssociative($array, $allStrings = true)
  • ArrayHelper::isIndexed($array, $consecutive = false)
  • ArrayHelper::isIn($needle, $haystack, $strict = false)
  • ArrayHelper::isTraversable($var)
  • ArrayHelper::isSubset($needles, $haystack, $strict = false)
  • ArrayHelper::filter($array, $filters)
  • ArrayHelper::recursiveSort(array &$array, $sorter = null)

Usage examples for ArrayHelper see in tests tests/Unit/ArrayHelperTest.php

Installation

The preferred way to install this extension is through composer.

Run the command in the terminal:

composer require "coderius/php-helpers"

Testing

  • Go to root folder in terminal and run tests:
php ./vendor/bin/phpunit