From c187f033afd8dee6429e0402415eef583a80eb32 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Tue, 17 Mar 2015 09:34:46 +0100 Subject: [PATCH 1/7] add travis config --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..62b6644 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: php +php: + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - hhvm +install: + - composer install --dev +script: + - ./vendor/bin/phpunit From 551b2e1189c483289bf7bfbfba72b1d85f785ab2 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Tue, 17 Mar 2015 14:44:27 +0100 Subject: [PATCH 2/7] conditionally set composer config --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 62b6644..04c2a50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,10 @@ php: - 5.6 - hhvm install: + - | + if $TRAVIS_SECURE_ENV_VARS; then + composer config github-oauth.github.com $GITHUB_OAUTH_TOKEN + fi - composer install --dev script: - ./vendor/bin/phpunit From 8531253c4307234ee3aefaffe86fa7a9b065ca15 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Tue, 17 Mar 2015 15:02:04 +0100 Subject: [PATCH 3/7] Add available methods to README --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7c0e75e..22b6d94 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,40 @@ -# php-array-utils -PHP array utility functions +# PHP array utility functions. + +This is a set of utility functions for array alteration and handling. + +They all follow the same naming conventions as the default methods in the form of `array_*`. + +## Functions + +#### `array_delete(array &$array, $key)` + +Deletes entry from array and return its value. + +_NB: This method modifies the original variable._ + +#### `array_get(array &$array, $key)` + +Lookup entry in array by key and return its value, returns `false` if not found. + +_NB: This method modifies the original variable._ + +#### ```array_flatten(array $array)``` + +Make multidimensional array flat. + +#### `array_pick(array $array, $keys)` + +Return array with only the keys in `$keys`. + +#### `array_reject(array $array, $keys)` + +Return array without the keys in `$keys`. +This is the inverse of `array_pick` + +## Contributing + +1. Fork it ( https://github.com/fetch/php-array-utils/fork ) +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create a new Pull Request From ac6a5f58bda522ba6ec413d0ae7546d676e317b1 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Tue, 17 Mar 2015 15:03:39 +0100 Subject: [PATCH 4/7] visualize optional $keys format --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 22b6d94..72f40dd 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,11 @@ _NB: This method modifies the original variable._ Make multidimensional array flat. -#### `array_pick(array $array, $keys)` +#### `array_pick(array $array, $keys[, $key[, $key]])` Return array with only the keys in `$keys`. -#### `array_reject(array $array, $keys)` +#### `array_reject(array $array, $keys[, $key[, $key]])` Return array without the keys in `$keys`. This is the inverse of `array_pick` From fd16976694da710de6b9a3ecfaf8b41a3100f3a8 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Tue, 17 Mar 2015 15:05:35 +0100 Subject: [PATCH 5/7] Add Travis CI badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 72f40dd..4cd7c0b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PHP array utility functions. +# PHP array utility functions. [![Build Status](https://travis-ci.org/fetch/php-array-utils.svg?branch=master)](https://travis-ci.org/fetch/php-array-utils) This is a set of utility functions for array alteration and handling. From a4d2dbf70dd36747d122ed69bb542a3afe699b16 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sat, 14 Nov 2015 12:35:56 +0100 Subject: [PATCH 6/7] optimize variable argument functions - only request all arguments when argument count is more than 2 - only test for keys to be an array when not the exceeding the number of arguments --- lib/array.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/array.php b/lib/array.php index 819b889..96cf215 100644 --- a/lib/array.php +++ b/lib/array.php @@ -74,11 +74,10 @@ function array_flatten(array $array){ * @return array */ function array_pick(array $array, $keys){ - $arguments = func_get_args(); if(func_num_args() > 2){ + $arguments = func_get_args(); $keys = array_slice($arguments, 1); - } - if(!is_array($keys)){ + }elseif(!is_array($keys)){ $keys = array($keys); } return array_intersect_key($array, array_flip($keys)); @@ -97,11 +96,10 @@ function array_pick(array $array, $keys){ * @return array */ function array_reject(array $array, $keys){ - $arguments = func_get_args(); if(func_num_args() > 2){ + $arguments = func_get_args(); $keys = array_slice($arguments, 1); - } - if(!is_array($keys)){ + }elseif(!is_array($keys)){ $keys = array($keys); } return array_diff_key($array, array_flip($keys)); From 459d9d7a77f58b7c2101611d464f4ac34fd8dd50 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sat, 14 Nov 2015 12:40:19 +0100 Subject: [PATCH 7/7] no need to have argument by reference in array_get --- README.md | 6 ++---- lib/array.php | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4cd7c0b..027d419 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,11 @@ Deletes entry from array and return its value. _NB: This method modifies the original variable._ -#### `array_get(array &$array, $key)` +#### `array_get(array $array, $key)` Lookup entry in array by key and return its value, returns `false` if not found. -_NB: This method modifies the original variable._ - -#### ```array_flatten(array $array)``` +#### `array_flatten(array $array)` Make multidimensional array flat. diff --git a/lib/array.php b/lib/array.php index 96cf215..48a90bf 100644 --- a/lib/array.php +++ b/lib/array.php @@ -30,7 +30,7 @@ function array_delete(array &$data, $key){ * @param string $key * @return mixed */ - function array_get(array &$data, $key){ + function array_get(array $data, $key){ if(array_key_exists($key, $data)){ return $data[$key]; }