Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Arrayy often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Arrayy, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class Arrayy extends \ArrayObject implements \Countable, \IteratorAggregate, \ArrayAccess, \Serializable |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var array |
||
| 19 | */ |
||
| 20 | protected $array = array(); |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Initializes |
||
| 24 | * |
||
| 25 | * @param array $array |
||
| 26 | */ |
||
| 27 | 667 | public function __construct($array = array()) |
|
| 33 | |||
| 34 | /** |
||
| 35 | * create a fallback for array |
||
| 36 | * |
||
| 37 | * 1. fallback to empty array, if there is nothing |
||
| 38 | * 2. cast a String or Object with "__toString" into an array |
||
| 39 | * 3. call "__toArray" on Object, if the method exists |
||
| 40 | * 4. throw a "InvalidArgumentException"-Exception |
||
| 41 | * |
||
| 42 | * @param $array |
||
| 43 | * |
||
| 44 | * @return array |
||
| 45 | */ |
||
| 46 | 667 | protected function fallbackForArray(&$array) |
|
| 47 | { |
||
| 48 | 667 | if (is_array($array)) { |
|
| 49 | 665 | return $array; |
|
| 50 | } |
||
| 51 | |||
| 52 | 5 | if ($array instanceof self) { |
|
| 53 | 1 | return $array->getArray(); |
|
| 54 | } |
||
| 55 | |||
| 56 | 4 | if (!$array) { |
|
| 57 | 1 | return array(); |
|
| 58 | } |
||
| 59 | |||
| 60 | if ( |
||
| 61 | 3 | is_string($array) |
|
| 62 | || |
||
| 63 | 3 | (is_object($array) && method_exists($array, '__toString')) |
|
| 64 | ) { |
||
| 65 | 1 | return (array)$array; |
|
| 66 | } |
||
| 67 | |||
| 68 | 2 | if (is_object($array) && method_exists($array, '__toArray')) { |
|
| 69 | return (array)$array->__toArray(); |
||
| 70 | } |
||
| 71 | |||
| 72 | 2 | throw new \InvalidArgumentException( |
|
| 73 | 2 | 'Passed value must be a array' |
|
| 74 | ); |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Get the current array from the "Arrayy"-object |
||
| 79 | * |
||
| 80 | * @return array |
||
| 81 | */ |
||
| 82 | 470 | public function getArray() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Create a new Arrayy object via string. |
||
| 89 | * |
||
| 90 | * @param string $str The input string. |
||
| 91 | * @param string|null $delimiter The boundary string. |
||
| 92 | * @param string|null $regEx Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be used. |
||
| 93 | * |
||
| 94 | * @return Arrayy Returns created instance |
||
| 95 | */ |
||
| 96 | 8 | public static function createFromString($str, $delimiter, $regEx = null) |
|
| 97 | { |
||
| 98 | 8 | if ($regEx) { |
|
|
|
|||
| 99 | 1 | preg_match_all($regEx, $str, $array); |
|
| 100 | |||
| 101 | 1 | if (count($array) > 0) { |
|
| 102 | 1 | $array = $array[0]; |
|
| 103 | } |
||
| 104 | |||
| 105 | } else { |
||
| 106 | 7 | $array = explode($delimiter, $str); |
|
| 107 | } |
||
| 108 | |||
| 109 | // trim all string in the array |
||
| 110 | 8 | array_walk( |
|
| 111 | $array, |
||
| 112 | function (&$val) { |
||
| 113 | 8 | if (is_string($val)) { |
|
| 114 | 8 | $val = trim($val); |
|
| 115 | } |
||
| 116 | 8 | } |
|
| 117 | ); |
||
| 118 | |||
| 119 | 8 | return static::create($array); |
|
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Creates a Arrayy object. |
||
| 124 | * |
||
| 125 | * @param array $array |
||
| 126 | * |
||
| 127 | * @return Arrayy Returns created instance |
||
| 128 | */ |
||
| 129 | 433 | public static function create($array = array()) |
|
| 133 | |||
| 134 | /** |
||
| 135 | * create a new Arrayy object via JSON, |
||
| 136 | * |
||
| 137 | * @param string $json |
||
| 138 | * |
||
| 139 | * @return Arrayy Returns created instance |
||
| 140 | */ |
||
| 141 | 5 | public static function createFromJson($json) |
|
| 147 | |||
| 148 | /** |
||
| 149 | * Create a new instance filled with values from an object implementing ArrayAccess. |
||
| 150 | * |
||
| 151 | * @param ArrayAccess $elements Object that implements ArrayAccess |
||
| 152 | * |
||
| 153 | * @return Arrayy Returns created instance |
||
| 154 | */ |
||
| 155 | 4 | public static function createFromObject(ArrayAccess $elements) |
|
| 156 | { |
||
| 157 | 4 | $array = new static(); |
|
| 158 | 4 | foreach ($elements as $key => $value) { |
|
| 159 | /** @noinspection OffsetOperationsInspection */ |
||
| 160 | 3 | $array[$key] = $value; |
|
| 161 | } |
||
| 162 | |||
| 163 | 4 | return $array; |
|
| 164 | } |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Create a new instance containing a range of elements. |
||
| 168 | * |
||
| 169 | * @param mixed $low First value of the sequence |
||
| 170 | * @param mixed $high The sequence is ended upon reaching the end value |
||
| 171 | * @param int $step Used as the increment between elements in the sequence |
||
| 172 | * |
||
| 173 | * @return Arrayy The created array |
||
| 174 | */ |
||
| 175 | 1 | public static function createWithRange($low, $high, $step = 1) |
|
| 179 | |||
| 180 | /** |
||
| 181 | * alias: for "Arrayy->random()" |
||
| 182 | * |
||
| 183 | * @return Arrayy |
||
| 184 | */ |
||
| 185 | 3 | public function getRandom() |
|
| 186 | { |
||
| 187 | 3 | return $this->random(); |
|
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Get a random value from the current array. |
||
| 192 | * |
||
| 193 | * @param null|int $number how many values you will take? |
||
| 194 | * |
||
| 195 | * @return Arrayy |
||
| 196 | */ |
||
| 197 | 27 | public function random($number = null) |
|
| 198 | { |
||
| 199 | 27 | if ($this->count() === 0) { |
|
| 200 | return static::create(); |
||
| 201 | } |
||
| 202 | |||
| 203 | 27 | if ($number === null) { |
|
| 204 | 15 | $arrayRandValue = (array)$this->array[array_rand($this->array)]; |
|
| 205 | |||
| 206 | 15 | return static::create($arrayRandValue); |
|
| 207 | } |
||
| 208 | |||
| 209 | 14 | shuffle($this->array); |
|
| 210 | |||
| 211 | 14 | return $this->first($number); |
|
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Count the values from the current array. |
||
| 216 | * |
||
| 217 | * INFO: only a alias for "$arrayy->size()" |
||
| 218 | * |
||
| 219 | * @return int |
||
| 220 | */ |
||
| 221 | 102 | public function count() |
|
| 225 | |||
| 226 | /** |
||
| 227 | * Get the size of an array. |
||
| 228 | * |
||
| 229 | * @return int |
||
| 230 | */ |
||
| 231 | 102 | public function size() |
|
| 235 | |||
| 236 | /** |
||
| 237 | * Get the first value(s) from the current array. |
||
| 238 | * |
||
| 239 | * @param int|null $number how many values you will take? |
||
| 240 | * |
||
| 241 | * @return Arrayy |
||
| 242 | */ |
||
| 243 | 43 | public function first($number = null) |
|
| 244 | { |
||
| 245 | 43 | if ($number === null) { |
|
| 246 | 12 | $array = (array)array_shift($this->array); |
|
| 247 | } else { |
||
| 248 | 31 | $number = (int)$number; |
|
| 249 | 31 | $array = array_splice($this->array, 0, $number, true); |
|
| 250 | } |
||
| 251 | |||
| 252 | 43 | return static::create($array); |
|
| 253 | } |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Append a value to an array. |
||
| 257 | * |
||
| 258 | * @param mixed $value |
||
| 259 | * |
||
| 260 | * @return Arrayy |
||
| 261 | */ |
||
| 262 | 8 | public function append($value) |
|
| 268 | |||
| 269 | /** |
||
| 270 | * @return mixed |
||
| 271 | */ |
||
| 272 | public function serialize() |
||
| 273 | { |
||
| 274 | return serialize($this->array); |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @param string $array |
||
| 279 | */ |
||
| 280 | public function unserialize($array) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Assigns a value to the specified offset. |
||
| 287 | * |
||
| 288 | * @param mixed $offset |
||
| 289 | * @param mixed $value |
||
| 290 | */ |
||
| 291 | 13 | public function offsetSet($offset, $value) |
|
| 299 | |||
| 300 | /** |
||
| 301 | * alias: for "Arrayy->randomValue()" |
||
| 302 | * |
||
| 303 | * @return mixed get a random value or null if there wasn't a value |
||
| 304 | */ |
||
| 305 | public function getRandomValue() |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Pick a random value from the values of this array. |
||
| 312 | * |
||
| 313 | * @return mixed get a random value or null if there wasn't a value |
||
| 314 | */ |
||
| 315 | View Code Duplication | public function randomValue() |
|
| 325 | |||
| 326 | /** |
||
| 327 | * alias: for "Arrayy->randomValues()" |
||
| 328 | * |
||
| 329 | * @param int $number |
||
| 330 | * |
||
| 331 | * @return Arrayy |
||
| 332 | */ |
||
| 333 | 6 | public function getRandomValues($number) |
|
| 337 | |||
| 338 | /** |
||
| 339 | * Pick a given number of random values out of this array. |
||
| 340 | * |
||
| 341 | * @param int $number |
||
| 342 | * |
||
| 343 | * @return Arrayy |
||
| 344 | */ |
||
| 345 | 6 | public function randomValues($number) |
|
| 351 | |||
| 352 | /** |
||
| 353 | * alias: for "Arrayy->randomKey()" |
||
| 354 | * |
||
| 355 | * @return mixed get a key/index or null if there wasn't a key/index |
||
| 356 | */ |
||
| 357 | 3 | public function getRandomKey() |
|
| 361 | |||
| 362 | /** |
||
| 363 | * Pick a random key/index from the keys of this array. |
||
| 364 | * |
||
| 365 | * |
||
| 366 | * @return mixed get a key/index or null if there wasn't a key/index |
||
| 367 | * |
||
| 368 | * @throws \RangeException If array is empty |
||
| 369 | */ |
||
| 370 | 3 | View Code Duplication | public function randomKey() |
| 380 | |||
| 381 | /** |
||
| 382 | * Pick a given number of random keys/indexes out of this array. |
||
| 383 | * |
||
| 384 | * @param int $number The number of keys/indexes (should be <= $this->count()) |
||
| 385 | * |
||
| 386 | * @return Arrayy |
||
| 387 | * |
||
| 388 | * @throws \RangeException If array is empty |
||
| 389 | */ |
||
| 390 | 12 | public function randomKeys($number) |
|
| 409 | |||
| 410 | /** |
||
| 411 | * alias: for "Arrayy->randomKeys()" |
||
| 412 | * |
||
| 413 | * @param int $number |
||
| 414 | * |
||
| 415 | * @return Arrayy |
||
| 416 | */ |
||
| 417 | 9 | public function getRandomKeys($number) |
|
| 421 | |||
| 422 | /** |
||
| 423 | * find by ... |
||
| 424 | * |
||
| 425 | * @param $property |
||
| 426 | * @param $value |
||
| 427 | * @param string $comparisonOp |
||
| 428 | * |
||
| 429 | * @return Arrayy |
||
| 430 | */ |
||
| 431 | public function findBy($property, $value, $comparisonOp = 'eq') |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular property |
||
| 440 | * within that. |
||
| 441 | * |
||
| 442 | * @param $property |
||
| 443 | * @param $value |
||
| 444 | * @param string $comparisonOp |
||
| 445 | * |
||
| 446 | * @return Arrayy |
||
| 447 | */ |
||
| 448 | 1 | public function filterBy($property, $value, $comparisonOp = null) |
|
| 507 | |||
| 508 | /** |
||
| 509 | * Get a value from an array (optional using dot-notation). |
||
| 510 | * |
||
| 511 | * @param string $key The key to look for |
||
| 512 | * @param mixed $default Default value to fallback to |
||
| 513 | * @param array $array The array to get from, |
||
| 514 | * if it's set to "null" we use the current array from the class |
||
| 515 | * |
||
| 516 | * @return mixed |
||
| 517 | */ |
||
| 518 | 31 | public function get($key, $default = null, $array = null) |
|
| 545 | |||
| 546 | /** |
||
| 547 | * WARNING: Creates a Arrayy object by reference. |
||
| 548 | * |
||
| 549 | * @param array $array |
||
| 550 | * |
||
| 551 | * @return $this |
||
| 552 | */ |
||
| 553 | public function createByReference(&$array = array()) |
||
| 561 | |||
| 562 | /** |
||
| 563 | * Get all values from a array. |
||
| 564 | * |
||
| 565 | * @return Arrayy |
||
| 566 | */ |
||
| 567 | 1 | public function values() |
|
| 573 | |||
| 574 | /** |
||
| 575 | * Group values from a array according to the results of a closure. |
||
| 576 | * |
||
| 577 | * @param string $grouper a callable function name |
||
| 578 | * @param bool $saveKeys |
||
| 579 | * |
||
| 580 | * @return Arrayy |
||
| 581 | */ |
||
| 582 | 3 | public function group($grouper, $saveKeys = false) |
|
| 607 | |||
| 608 | /** |
||
| 609 | * Given a list and an iterate-function that returns |
||
| 610 | * a key for each element in the list (or a property name), |
||
| 611 | * returns an object with an index of each item. |
||
| 612 | * |
||
| 613 | * Just like groupBy, but for when you know your keys are unique. |
||
| 614 | * |
||
| 615 | * @param mixed $key |
||
| 616 | * |
||
| 617 | * @return Arrayy |
||
| 618 | */ |
||
| 619 | 3 | public function indexBy($key) |
|
| 631 | |||
| 632 | /** |
||
| 633 | * magic to string |
||
| 634 | * |
||
| 635 | * @return string |
||
| 636 | */ |
||
| 637 | 17 | public function __toString() |
|
| 641 | |||
| 642 | /** |
||
| 643 | * Implodes array to a string with specified separator. |
||
| 644 | * |
||
| 645 | * @param string $separator The element's separator |
||
| 646 | * |
||
| 647 | * @return string The string representation of array, separated by "," |
||
| 648 | */ |
||
| 649 | 17 | public function toString($separator = ',') |
|
| 653 | |||
| 654 | /** |
||
| 655 | * Implodes an array. |
||
| 656 | * |
||
| 657 | * @param string $with What to implode it with |
||
| 658 | * |
||
| 659 | * @return string |
||
| 660 | */ |
||
| 661 | 25 | public function implode($with = '') |
|
| 665 | |||
| 666 | /** |
||
| 667 | * Push one or more values onto the end of array at once. |
||
| 668 | * |
||
| 669 | * @return $this An Arrayy object with pushed elements to the end of array |
||
| 670 | */ |
||
| 671 | 4 | View Code Duplication | public function push(/* variadic arguments allowed */) |
| 680 | |||
| 681 | /** |
||
| 682 | * Shifts a specified value off the beginning of array. |
||
| 683 | * |
||
| 684 | * @return mixed A shifted element from the current array. |
||
| 685 | */ |
||
| 686 | 4 | public function shift() |
|
| 690 | |||
| 691 | /** |
||
| 692 | * Prepends one or more values to the beginning of array at once. |
||
| 693 | * |
||
| 694 | * @return Arrayy Array object with prepended elements to the beginning of array |
||
| 695 | */ |
||
| 696 | 4 | View Code Duplication | public function unshift(/* variadic arguments allowed */) |
| 705 | |||
| 706 | /** |
||
| 707 | * Get a value by key. |
||
| 708 | * |
||
| 709 | * @param $key |
||
| 710 | * |
||
| 711 | * @return mixed |
||
| 712 | */ |
||
| 713 | public function &__get($key) |
||
| 717 | |||
| 718 | /** |
||
| 719 | * Assigns a value to the specified element. |
||
| 720 | * |
||
| 721 | * @param $key |
||
| 722 | * @param $value |
||
| 723 | */ |
||
| 724 | public function __set($key, $value) |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Whether or not an element exists by key. |
||
| 731 | * |
||
| 732 | * @param $key |
||
| 733 | * |
||
| 734 | * @return bool |
||
| 735 | */ |
||
| 736 | public function __isset($key) |
||
| 740 | * Whether or not an offset exists. |
||
| 741 | * |
||
| 742 | * @param mixed $offset |
||
| 743 | * |
||
| 744 | * @return bool |
||
| 745 | */ |
||
| 746 | 24 | public function offsetExists($offset) |
|
| 750 | |||
| 751 | /** |
||
| 752 | * Unset element by key |
||
| 753 | * |
||
| 754 | * @param mixed $key |
||
| 755 | */ |
||
| 756 | public function __unset($key) |
||
| 760 | |||
| 761 | /** |
||
| 762 | * Call object as function. |
||
| 763 | * |
||
| 764 | * @param mixed $key |
||
| 765 | * |
||
| 766 | * @return mixed |
||
| 767 | */ |
||
| 768 | public function __invoke($key = null) |
||
| 780 | |||
| 781 | /** |
||
| 782 | * Search for the value of the current array via $index. |
||
| 783 | * |
||
| 784 | * @param mixed $index |
||
| 785 | * |
||
| 786 | * @return Arrayy will return a empty Arrayy if the value wasn't found |
||
| 787 | */ |
||
| 788 | 7 | public function searchValue($index) |
|
| 803 | |||
| 804 | /** |
||
| 805 | * Check if all items in current array match a truth test. |
||
| 806 | * |
||
| 807 | * @param \Closure $closure |
||
| 808 | * |
||
| 809 | * @return bool |
||
| 810 | */ |
||
| 811 | 9 | View Code Duplication | public function matches(\Closure $closure) |
| 825 | |||
| 826 | /** |
||
| 827 | * Iterate over the current array and modify the array's value. |
||
| 828 | * |
||
| 829 | * @param \Closure $closure |
||
| 830 | * |
||
| 831 | * @return Arrayy |
||
| 832 | */ |
||
| 833 | 22 | View Code Duplication | public function each(\Closure $closure) |
| 843 | |||
| 844 | /** |
||
| 845 | * alias: for "Arrayy->getArray()" |
||
| 846 | */ |
||
| 847 | 153 | public function toArray() |
|
| 851 | |||
| 852 | /** |
||
| 853 | * Check if any item in the current array matches a truth test. |
||
| 854 | * |
||
| 855 | * @param \Closure $closure |
||
| 856 | * |
||
| 857 | * @return bool |
||
| 858 | */ |
||
| 859 | 9 | View Code Duplication | public function matchesAny(\Closure $closure) |
| 873 | |||
| 874 | /** |
||
| 875 | * Check whether array is associative or not. |
||
| 876 | * |
||
| 877 | * @return bool Returns true if associative, false otherwise |
||
| 878 | */ |
||
| 879 | 14 | public function isAssoc() |
|
| 893 | |||
| 894 | /** |
||
| 895 | * Unset an offset. |
||
| 896 | * |
||
| 897 | * @param mixed $offset |
||
| 898 | */ |
||
| 899 | 5 | public function offsetUnset($offset) |
|
| 905 | |||
| 906 | /** |
||
| 907 | * Check whether the array is empty or not. |
||
| 908 | * |
||
| 909 | * @return bool Returns true if empty, false otherwise |
||
| 910 | */ |
||
| 911 | 22 | public function isEmpty() |
|
| 915 | |||
| 916 | /** |
||
| 917 | * alias: for "Arrayy->keys()" |
||
| 918 | * |
||
| 919 | * @return Arrayy |
||
| 920 | */ |
||
| 921 | 15 | public function getKeys() |
|
| 925 | |||
| 926 | /** |
||
| 927 | * Get all keys from the current array. |
||
| 928 | * |
||
| 929 | * @return Arrayy |
||
| 930 | */ |
||
| 931 | 20 | public function keys() |
|
| 937 | |||
| 938 | /** |
||
| 939 | * Check whether array is numeric or not. |
||
| 940 | * |
||
| 941 | * @return bool Returns true if numeric, false otherwise |
||
| 942 | */ |
||
| 943 | 4 | public function isNumeric() |
|
| 957 | |||
| 958 | /** |
||
| 959 | * Check if the current array is a multi-array. |
||
| 960 | * |
||
| 961 | * @return bool |
||
| 962 | */ |
||
| 963 | 13 | public function isMultiArray() |
|
| 967 | |||
| 968 | /** |
||
| 969 | * Check if an item is in the current array. |
||
| 970 | * |
||
| 971 | * @param mixed $value |
||
| 972 | * |
||
| 973 | * @return bool |
||
| 974 | */ |
||
| 975 | 13 | public function contains($value) |
|
| 979 | |||
| 980 | /** |
||
| 981 | * Check if the given key/index exists in the array. |
||
| 982 | * |
||
| 983 | * @param mixed $key Key/index to search for |
||
| 984 | * |
||
| 985 | * @return bool Returns true if the given key/index exists in the array, false otherwise |
||
| 986 | */ |
||
| 987 | 4 | public function containsKey($key) |
|
| 991 | |||
| 992 | /** |
||
| 993 | * Returns the average value of the current array. |
||
| 994 | * |
||
| 995 | * @param int $decimals The number of decimals to return |
||
| 996 | * |
||
| 997 | * @return int|double The average value |
||
| 998 | */ |
||
| 999 | 10 | public function average($decimals = null) |
|
| 1013 | * Returns the value at specified offset. |
||
| 1014 | * |
||
| 1015 | * @param mixed $offset |
||
| 1016 | * |
||
| 1017 | * @return mixed return null if the offset did not exists |
||
| 1018 | */ |
||
| 1019 | 15 | public function offsetGet($offset) |
|
| 1023 | |||
| 1024 | /** |
||
| 1025 | * Count the values from the current array. |
||
| 1026 | * |
||
| 1027 | * INFO: only a alias for "$arrayy->size()" |
||
| 1028 | * |
||
| 1029 | * @return int |
||
| 1030 | */ |
||
| 1031 | 10 | public function length() |
|
| 1035 | |||
| 1036 | /** |
||
| 1037 | * Get the max value from an array. |
||
| 1038 | * |
||
| 1039 | * @return mixed |
||
| 1040 | */ |
||
| 1041 | 10 | public function max() |
|
| 1049 | |||
| 1050 | /** |
||
| 1051 | * Get the min value from an array. |
||
| 1052 | * |
||
| 1053 | * @return mixed |
||
| 1054 | */ |
||
| 1055 | 10 | public function min() |
|
| 1063 | |||
| 1064 | /** |
||
| 1065 | * Find the first item in an array that passes the truth test, |
||
| 1066 | * otherwise return false |
||
| 1067 | * |
||
| 1068 | * @param \Closure $closure |
||
| 1069 | * |
||
| 1070 | * @return mixed|false false if we did not find the value |
||
| 1071 | */ |
||
| 1072 | 8 | public function find(\Closure $closure) |
|
| 1082 | |||
| 1083 | /** |
||
| 1084 | * WARNING!!! -> Clear the current array. |
||
| 1085 | * |
||
| 1086 | * @return $this will always return an empty Arrayy object |
||
| 1087 | */ |
||
| 1088 | 4 | public function clear() |
|
| 1094 | |||
| 1095 | /** |
||
| 1096 | * Clean all falsy values from an array. |
||
| 1097 | * |
||
| 1098 | * @return Arrayy |
||
| 1099 | */ |
||
| 1100 | 8 | public function clean() |
|
| 1108 | |||
| 1109 | /** |
||
| 1110 | * Find all items in an array that pass the truth test. |
||
| 1111 | * |
||
| 1112 | * @param \Closure|null $closure |
||
| 1113 | * |
||
| 1114 | * @return Arrayy |
||
| 1115 | */ |
||
| 1116 | 8 | public function filter($closure = null) |
|
| 1126 | |||
| 1127 | /** |
||
| 1128 | * Get a random value from an array, with the ability to skew the results. |
||
| 1129 | * |
||
| 1130 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
| 1131 | * |
||
| 1132 | * @param array $array |
||
| 1133 | * @param null|int $number how many values you will take? |
||
| 1134 | * |
||
| 1135 | * @return Arrayy |
||
| 1136 | */ |
||
| 1137 | 9 | public function randomWeighted(array $array, $number = null) |
|
| 1150 | * Returns a new ArrayIterator, thus implementing the IteratorAggregate interface. |
||
| 1151 | * |
||
| 1152 | * @return \ArrayIterator An iterator for the values in the array. |
||
| 1153 | */ |
||
| 1154 | 16 | public function getIterator() |
|
| 1158 | |||
| 1159 | /** |
||
| 1160 | * Search for the first index of the current array via $value. |
||
| 1161 | * |
||
| 1162 | * @param mixed $value |
||
| 1163 | * |
||
| 1164 | * @return mixed |
||
| 1165 | */ |
||
| 1166 | 20 | public function searchIndex($value) |
|
| 1170 | |||
| 1171 | /** |
||
| 1172 | * Merge the new $array into the current array. |
||
| 1173 | * |
||
| 1174 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 1175 | * |
||
| 1176 | * @param array $array |
||
| 1177 | * @param bool $recursive |
||
| 1178 | * |
||
| 1179 | * @return Arrayy |
||
| 1180 | */ |
||
| 1181 | 25 | View Code Duplication | public function mergeAppendKeepIndex(array $array = array(), $recursive = false) |
| 1191 | |||
| 1192 | /** |
||
| 1193 | * alias: for "Arrayy->searchIndex()" |
||
| 1194 | * |
||
| 1195 | * @param mixed $value Value to search for |
||
| 1196 | * |
||
| 1197 | * @return mixed |
||
| 1198 | */ |
||
| 1199 | 4 | public function indexOf($value) |
|
| 1203 | |||
| 1204 | /** |
||
| 1205 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 1206 | * |
||
| 1207 | * @param array $search |
||
| 1208 | * |
||
| 1209 | * @return bool |
||
| 1210 | */ |
||
| 1211 | 1 | public function intersects(array $search) |
|
| 1215 | |||
| 1216 | /** |
||
| 1217 | * Return an array with all elements found in input array. |
||
| 1218 | * |
||
| 1219 | * @param array $search |
||
| 1220 | * |
||
| 1221 | * @return Arrayy |
||
| 1222 | */ |
||
| 1223 | 2 | public function intersection(array $search) |
|
| 1229 | |||
| 1230 | /** |
||
| 1231 | * Get the last value(s) from the current array. |
||
| 1232 | * |
||
| 1233 | * @param int|null $number |
||
| 1234 | * |
||
| 1235 | * @return Arrayy |
||
| 1236 | */ |
||
| 1237 | 15 | public function last($number = null) |
|
| 1249 | |||
| 1250 | /** |
||
| 1251 | * Pop a specified value off the end of the current array. |
||
| 1252 | * |
||
| 1253 | * @return mixed The popped element from the current array. |
||
| 1254 | */ |
||
| 1255 | 15 | public function pop() |
|
| 1259 | |||
| 1260 | /** |
||
| 1261 | * Get the last elements from index $from until the end of this array. |
||
| 1262 | * |
||
| 1263 | * @param int $from |
||
| 1264 | * |
||
| 1265 | * @return Arrayy |
||
| 1266 | */ |
||
| 1267 | 16 | public function rest($from = 1) |
|
| 1273 | |||
| 1274 | /** |
||
| 1275 | * Get everything but the last..$to items. |
||
| 1276 | * |
||
| 1277 | * @param int $to |
||
| 1278 | * |
||
| 1279 | * @return Arrayy |
||
| 1280 | */ |
||
| 1281 | 12 | public function initial($to = 1) |
|
| 1287 | |||
| 1288 | /** |
||
| 1289 | * Extract a slice of the array. |
||
| 1290 | * |
||
| 1291 | * @param int $offset Slice begin index |
||
| 1292 | * @param int|null $length Length of the slice |
||
| 1293 | * @param bool $preserveKeys Whether array keys are preserved or no |
||
| 1294 | * |
||
| 1295 | * @return static A slice of the original array with length $length |
||
| 1296 | */ |
||
| 1297 | 4 | public function slice($offset, $length = null, $preserveKeys = false) |
|
| 1303 | |||
| 1304 | /** |
||
| 1305 | * Iterate over an array and execute a callback for each loop. |
||
| 1306 | * |
||
| 1307 | * @param \Closure $closure |
||
| 1308 | * |
||
| 1309 | * @return Arrayy |
||
| 1310 | */ |
||
| 1311 | 2 | View Code Duplication | public function at(\Closure $closure) |
| 1321 | |||
| 1322 | /** |
||
| 1323 | * Merge the new $array into the current array. |
||
| 1324 | * |
||
| 1325 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 1326 | * - create new indexes |
||
| 1327 | * |
||
| 1328 | * @param array $array |
||
| 1329 | * @param bool $recursive |
||
| 1330 | * |
||
| 1331 | * @return Arrayy |
||
| 1332 | */ |
||
| 1333 | 16 | View Code Duplication | public function mergeAppendNewIndex(array $array = array(), $recursive = false) |
| 1343 | |||
| 1344 | /** |
||
| 1345 | * Merge the current array into the new $array. |
||
| 1346 | * |
||
| 1347 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 1348 | * - create new indexes |
||
| 1349 | * |
||
| 1350 | * @param array $array |
||
| 1351 | * @param bool $recursive |
||
| 1352 | * |
||
| 1353 | * @return Arrayy |
||
| 1354 | */ |
||
| 1355 | 16 | View Code Duplication | public function mergePrependNewIndex(array $array = array(), $recursive = false) |
| 1365 | |||
| 1366 | /** |
||
| 1367 | * Merge the the current array into the $array. |
||
| 1368 | * |
||
| 1369 | * - use key,value from the new $array, also if the index is in the current array |
||
| 1370 | * |
||
| 1371 | * @param array $array |
||
| 1372 | * @param bool $recursive |
||
| 1373 | * |
||
| 1374 | * @return Arrayy |
||
| 1375 | */ |
||
| 1376 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = array(), $recursive = false) |
| 1386 | |||
| 1387 | /** |
||
| 1388 | * Return values that are only in the current array. |
||
| 1389 | * |
||
| 1390 | * @param array $array |
||
| 1391 | * |
||
| 1392 | * @return Arrayy |
||
| 1393 | */ |
||
| 1394 | 12 | public function diff(array $array = array()) |
|
| 1400 | |||
| 1401 | /** |
||
| 1402 | * Return values that are only in the new $array. |
||
| 1403 | * |
||
| 1404 | * @param array $array |
||
| 1405 | * |
||
| 1406 | * @return Arrayy |
||
| 1407 | */ |
||
| 1408 | 8 | public function diffReverse(array $array = array()) |
|
| 1414 | |||
| 1415 | /** |
||
| 1416 | * Replace the first matched value in an array. |
||
| 1417 | * |
||
| 1418 | * @param mixed $search |
||
| 1419 | * @param mixed $replacement |
||
| 1420 | * |
||
| 1421 | * @return Arrayy |
||
| 1422 | */ |
||
| 1423 | 3 | public function replaceOneValue($search, $replacement = '') |
|
| 1434 | |||
| 1435 | /** |
||
| 1436 | * Replace values in the current array. |
||
| 1437 | * |
||
| 1438 | * @param string $search The string to replace. |
||
| 1439 | * @param string $replacement What to replace it with. |
||
| 1440 | * |
||
| 1441 | * @return Arrayy |
||
| 1442 | */ |
||
| 1443 | 1 | public function replaceValues($search, $replacement = '') |
|
| 1453 | |||
| 1454 | /** |
||
| 1455 | * Replace the keys in an array with another set. |
||
| 1456 | * |
||
| 1457 | * @param array $keys An array of keys matching the array's size |
||
| 1458 | * |
||
| 1459 | * @return Arrayy |
||
| 1460 | */ |
||
| 1461 | 1 | public function replaceKeys(array $keys) |
|
| 1468 | |||
| 1469 | /** |
||
| 1470 | * Create an array using the current array as keys and the other array as values. |
||
| 1471 | * |
||
| 1472 | * @param array $array Values array |
||
| 1473 | * |
||
| 1474 | * @return Arrayy Arrayy object with values from the other array. |
||
| 1475 | */ |
||
| 1476 | 1 | public function replaceAllValues(array $array) |
|
| 1482 | |||
| 1483 | /** |
||
| 1484 | * Create an array using the current array as values and the other array as keys. |
||
| 1485 | * |
||
| 1486 | * @param array $keys Keys array |
||
| 1487 | * |
||
| 1488 | * @return Arrayy Arrayy object with keys from the other array. |
||
| 1489 | */ |
||
| 1490 | 1 | public function replaceAllKeys(array $keys) |
|
| 1496 | |||
| 1497 | /** |
||
| 1498 | * Shuffle the current array. |
||
| 1499 | * |
||
| 1500 | * @return Arrayy |
||
| 1501 | */ |
||
| 1502 | 1 | public function shuffle() |
|
| 1510 | |||
| 1511 | /** |
||
| 1512 | * Split an array in the given amount of pieces. |
||
| 1513 | * |
||
| 1514 | * @param int $numberOfPieces |
||
| 1515 | * @param bool $keepKeys |
||
| 1516 | * |
||
| 1517 | * @return array |
||
| 1518 | */ |
||
| 1519 | 1 | public function split($numberOfPieces = 2, $keepKeys = false) |
|
| 1531 | |||
| 1532 | /** |
||
| 1533 | * Create a chunked version of this array. |
||
| 1534 | * |
||
| 1535 | * @param int $size Size of each chunk |
||
| 1536 | * @param bool $preserveKeys Whether array keys are preserved or no |
||
| 1537 | * |
||
| 1538 | * @return static A new array of chunks from the original array |
||
| 1539 | */ |
||
| 1540 | 4 | public function chunk($size, $preserveKeys = false) |
|
| 1546 | |||
| 1547 | /** |
||
| 1548 | * Returns the values from a single column of the input array, identified by |
||
| 1549 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 1550 | * |
||
| 1551 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 1552 | * array by the values from the $indexKey column in the input array. |
||
| 1553 | * |
||
| 1554 | * @param mixed $columnKey |
||
| 1555 | * @param mixed $indexKey |
||
| 1556 | * |
||
| 1557 | * @return Arrayy |
||
| 1558 | */ |
||
| 1559 | 1 | public function getColumn($columnKey = null, $indexKey = null) |
|
| 1565 | |||
| 1566 | /** |
||
| 1567 | * Invoke a function on all of an array's values. |
||
| 1568 | * |
||
| 1569 | * @param mixed $callable |
||
| 1570 | * @param array $arguments |
||
| 1571 | * |
||
| 1572 | * @return Arrayy |
||
| 1573 | */ |
||
| 1574 | 1 | public function invoke($callable, $arguments = array()) |
|
| 1590 | |||
| 1591 | /** |
||
| 1592 | * Apply the given function to the every element of the array, |
||
| 1593 | * collecting the results. |
||
| 1594 | * |
||
| 1595 | * @param callable $callable |
||
| 1596 | * |
||
| 1597 | * @return Arrayy Arrayy object with modified elements |
||
| 1598 | */ |
||
| 1599 | 4 | public function map($callable) |
|
| 1605 | |||
| 1606 | /** |
||
| 1607 | * Check if a value is in the current array using a closure. |
||
| 1608 | * |
||
| 1609 | * @param \Closure $closure |
||
| 1610 | * |
||
| 1611 | * @return bool Returns true if the given value is found, false otherwise |
||
| 1612 | */ |
||
| 1613 | 4 | public function exists(\Closure $closure) |
|
| 1625 | |||
| 1626 | /** |
||
| 1627 | * Return all items that fail the truth test. |
||
| 1628 | * |
||
| 1629 | * @param \Closure $closure |
||
| 1630 | * |
||
| 1631 | * @return Arrayy |
||
| 1632 | */ |
||
| 1633 | 1 | View Code Duplication | public function reject(\Closure $closure) |
| 1645 | |||
| 1646 | /** |
||
| 1647 | * Replace a key with a new key/value pair. |
||
| 1648 | * |
||
| 1649 | * @param $replace |
||
| 1650 | * @param $key |
||
| 1651 | * @param $value |
||
| 1652 | * |
||
| 1653 | * @return Arrayy |
||
| 1654 | */ |
||
| 1655 | 1 | public function replace($replace, $key, $value) |
|
| 1661 | |||
| 1662 | /** |
||
| 1663 | * Remove a value from the current array (optional using dot-notation). |
||
| 1664 | * |
||
| 1665 | * @param mixed $key |
||
| 1666 | * |
||
| 1667 | * @return Arrayy |
||
| 1668 | */ |
||
| 1669 | 17 | public function remove($key) |
|
| 1684 | |||
| 1685 | /** |
||
| 1686 | * Internal mechanics of remove method. |
||
| 1687 | * |
||
| 1688 | * @param $key |
||
| 1689 | * |
||
| 1690 | * @return boolean |
||
| 1691 | */ |
||
| 1692 | 17 | protected function internalRemove($key) |
|
| 1714 | |||
| 1715 | /** |
||
| 1716 | * Check if an array has a given key. |
||
| 1717 | * |
||
| 1718 | * @param mixed $key |
||
| 1719 | * |
||
| 1720 | * @return bool |
||
| 1721 | */ |
||
| 1722 | 18 | public function has($key) |
|
| 1729 | |||
| 1730 | /** |
||
| 1731 | * Set a value for the current array (optional using dot-notation). |
||
| 1732 | * |
||
| 1733 | * @param string $key The key to set |
||
| 1734 | * @param mixed $value Its value |
||
| 1735 | * |
||
| 1736 | * @return Arrayy |
||
| 1737 | */ |
||
| 1738 | 14 | public function set($key, $value) |
|
| 1744 | |||
| 1745 | /** |
||
| 1746 | * Internal mechanic of set method. |
||
| 1747 | * |
||
| 1748 | * @param mixed $key |
||
| 1749 | * @param mixed $value |
||
| 1750 | * |
||
| 1751 | * @return bool |
||
| 1752 | */ |
||
| 1753 | 14 | protected function internalSet($key, $value) |
|
| 1777 | |||
| 1778 | /** |
||
| 1779 | * Get a value from a array and set it if it was not. |
||
| 1780 | * |
||
| 1781 | * WARNING: this method only set the value, if the $key is not already set |
||
| 1782 | * |
||
| 1783 | * @param string $key The key |
||
| 1784 | * @param mixed $default The default value to set if it isn't |
||
| 1785 | * |
||
| 1786 | * @return mixed |
||
| 1787 | */ |
||
| 1788 | 9 | public function setAndGet($key, $default = null) |
|
| 1797 | |||
| 1798 | /** |
||
| 1799 | * Remove the first value from the current array. |
||
| 1800 | * |
||
| 1801 | * @return Arrayy |
||
| 1802 | */ |
||
| 1803 | 7 | public function removeFirst() |
|
| 1809 | |||
| 1810 | /** |
||
| 1811 | * Remove the last value from the current array. |
||
| 1812 | * |
||
| 1813 | * @return Arrayy |
||
| 1814 | */ |
||
| 1815 | 7 | public function removeLast() |
|
| 1821 | |||
| 1822 | /** |
||
| 1823 | * Removes a particular value from an array (numeric or associative). |
||
| 1824 | * |
||
| 1825 | * @param mixed $value |
||
| 1826 | * |
||
| 1827 | * @return Arrayy |
||
| 1828 | */ |
||
| 1829 | 7 | public function removeValue($value) |
|
| 1847 | |||
| 1848 | /** |
||
| 1849 | * Pad array to the specified size with a given value. |
||
| 1850 | * |
||
| 1851 | * @param int $size Size of the result array |
||
| 1852 | * @param mixed $value Empty value by default |
||
| 1853 | * |
||
| 1854 | * @return Arrayy Arrayy object padded to $size with $value |
||
| 1855 | */ |
||
| 1856 | 4 | public function pad($size, $value) |
|
| 1862 | |||
| 1863 | /** |
||
| 1864 | * Prepend a value to an array. |
||
| 1865 | * |
||
| 1866 | * @param mixed $value |
||
| 1867 | * |
||
| 1868 | * @return Arrayy |
||
| 1869 | */ |
||
| 1870 | 7 | public function prepend($value) |
|
| 1876 | |||
| 1877 | /** |
||
| 1878 | * alias: for "Arrayy->append()" |
||
| 1879 | * |
||
| 1880 | * @param $value |
||
| 1881 | * |
||
| 1882 | * @return $this |
||
| 1883 | */ |
||
| 1884 | 1 | public function add($value) |
|
| 1890 | |||
| 1891 | /** |
||
| 1892 | * Create a numerically re-indexed Arrayy object. |
||
| 1893 | * |
||
| 1894 | * @return Arrayy The new instance with re-indexed array-elements |
||
| 1895 | */ |
||
| 1896 | 8 | public function reindex() |
|
| 1902 | |||
| 1903 | /** |
||
| 1904 | * Return the array in the reverse order. |
||
| 1905 | * |
||
| 1906 | * @return Arrayy |
||
| 1907 | */ |
||
| 1908 | 7 | public function reverse() |
|
| 1914 | |||
| 1915 | /** |
||
| 1916 | * Custom sort by value via "usort" |
||
| 1917 | * |
||
| 1918 | * @link http://php.net/manual/en/function.usort.php |
||
| 1919 | * |
||
| 1920 | * @param callable $func |
||
| 1921 | * |
||
| 1922 | * @return $this |
||
| 1923 | */ |
||
| 1924 | 4 | public function customSortValues($func) |
|
| 1930 | |||
| 1931 | /** |
||
| 1932 | * Custom sort by index via "uksort" |
||
| 1933 | * |
||
| 1934 | * @link http://php.net/manual/en/function.uksort.php |
||
| 1935 | * |
||
| 1936 | * @param callable $func |
||
| 1937 | * |
||
| 1938 | * @return $this |
||
| 1939 | */ |
||
| 1940 | 4 | public function customSortKeys($func) |
|
| 1946 | |||
| 1947 | /** |
||
| 1948 | * Sort the current array by key. |
||
| 1949 | * |
||
| 1950 | * @link http://php.net/manual/en/function.ksort.php |
||
| 1951 | * @link http://php.net/manual/en/function.krsort.php |
||
| 1952 | * |
||
| 1953 | * @param int|string $direction use SORT_ASC or SORT_DESC |
||
| 1954 | * @param int $strategy use e.g.: SORT_REGULAR or SORT_NATURAL |
||
| 1955 | * |
||
| 1956 | * @return $this |
||
| 1957 | */ |
||
| 1958 | 18 | public function sortKeys($direction = SORT_ASC, $strategy = SORT_REGULAR) |
|
| 1964 | |||
| 1965 | /** |
||
| 1966 | * sorting keys |
||
| 1967 | * |
||
| 1968 | * @param array $elements |
||
| 1969 | * @param int $direction |
||
| 1970 | * @param int $strategy |
||
| 1971 | */ |
||
| 1972 | 18 | protected function sorterKeys(array &$elements, $direction = SORT_ASC, $strategy = SORT_REGULAR) |
|
| 1987 | |||
| 1988 | /** |
||
| 1989 | * Get correct PHP constant for direction. |
||
| 1990 | * |
||
| 1991 | * @param int|string $direction |
||
| 1992 | * |
||
| 1993 | * @return int |
||
| 1994 | */ |
||
| 1995 | 38 | protected function getDirection($direction) |
|
| 2017 | |||
| 2018 | /** |
||
| 2019 | * Sort the current array by value. |
||
| 2020 | * |
||
| 2021 | * @param int $direction use SORT_ASC or SORT_DESC |
||
| 2022 | * @param int $strategy use e.g.: SORT_REGULAR or SORT_NATURAL |
||
| 2023 | * |
||
| 2024 | * @return Arrayy |
||
| 2025 | */ |
||
| 2026 | 1 | public function sortValueKeepIndex($direction = SORT_ASC, $strategy = SORT_REGULAR) |
|
| 2030 | |||
| 2031 | /** |
||
| 2032 | * Sort the current array and optional you can keep the keys. |
||
| 2033 | * |
||
| 2034 | * @param string|int $direction use SORT_ASC or SORT_DESC |
||
| 2035 | * @param int|string $strategy |
||
| 2036 | * @param bool $keepKeys |
||
| 2037 | * |
||
| 2038 | * @return Arrayy |
||
| 2039 | */ |
||
| 2040 | 19 | public function sort($direction = SORT_ASC, $strategy = SORT_REGULAR, $keepKeys = false) |
|
| 2046 | |||
| 2047 | /** |
||
| 2048 | * @param array &$elements |
||
| 2049 | * @param int|string $direction |
||
| 2050 | * @param int $strategy |
||
| 2051 | * @param bool $keepKeys |
||
| 2052 | */ |
||
| 2053 | 19 | protected function sorting(array &$elements, $direction = SORT_ASC, $strategy = SORT_REGULAR, $keepKeys = false) |
|
| 2080 | |||
| 2081 | /** |
||
| 2082 | * Sort the current array by value. |
||
| 2083 | * |
||
| 2084 | * @param int $direction use SORT_ASC or SORT_DESC |
||
| 2085 | * @param int $strategy use e.g.: SORT_REGULAR or SORT_NATURAL |
||
| 2086 | * |
||
| 2087 | * @return Arrayy |
||
| 2088 | */ |
||
| 2089 | 1 | public function sortValueNewIndex($direction = SORT_ASC, $strategy = SORT_REGULAR) |
|
| 2093 | |||
| 2094 | /** |
||
| 2095 | * Sort a array by value, by a closure or by a property. |
||
| 2096 | * |
||
| 2097 | * - If the sorter is null, the array is sorted naturally. |
||
| 2098 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 2099 | * |
||
| 2100 | * @param null $sorter |
||
| 2101 | * @param string|int $direction |
||
| 2102 | * @param int $strategy |
||
| 2103 | * |
||
| 2104 | * @return Arrayy |
||
| 2105 | */ |
||
| 2106 | 1 | public function sorter($sorter = null, $direction = SORT_ASC, $strategy = SORT_REGULAR) |
|
| 2132 | |||
| 2133 | /** |
||
| 2134 | * Exchanges all keys with their associated values in an array. |
||
| 2135 | * |
||
| 2136 | * @return Arrayy |
||
| 2137 | */ |
||
| 2138 | 1 | public function flip() |
|
| 2144 | |||
| 2145 | /** |
||
| 2146 | * Apply the given function to every element in the array, |
||
| 2147 | * discarding the results. |
||
| 2148 | * |
||
| 2149 | * @param callable $callable |
||
| 2150 | * @param bool $recursive Whether array will be walked recursively or no |
||
| 2151 | * |
||
| 2152 | * @return Arrayy An Arrayy object with modified elements |
||
| 2153 | */ |
||
| 2154 | 8 | public function walk($callable, $recursive = false) |
|
| 2164 | |||
| 2165 | /** |
||
| 2166 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 2167 | * |
||
| 2168 | * @param mixed $callable |
||
| 2169 | * @param array $init |
||
| 2170 | * |
||
| 2171 | * @return Arrayy |
||
| 2172 | */ |
||
| 2173 | 2 | public function reduce($callable, array $init = array()) |
|
| 2179 | |||
| 2180 | /** |
||
| 2181 | * Return a duplicate free copy of the current array. |
||
| 2182 | * |
||
| 2183 | * @return Arrayy |
||
| 2184 | */ |
||
| 2185 | 7 | public function unique() |
|
| 2201 | |||
| 2202 | /** |
||
| 2203 | * Convert the current array to JSON. |
||
| 2204 | * |
||
| 2205 | * @param null $options e.g. JSON_PRETTY_PRINT |
||
| 2206 | * |
||
| 2207 | * @return string |
||
| 2208 | */ |
||
| 2209 | 5 | public function toJson($options = null) |
|
| 2213 | |||
| 2214 | |||
| 2215 | |||
| 2216 | |||
| 2217 | |||
| 2218 | |||
| 2219 | |||
| 2220 | |||
| 2221 | |||
| 2222 | |||
| 2223 | } |
||
| 2224 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: