-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support php5.5 * remove mkdocs from travis file * add markdown linting * use mt_rand * handle sequential arrays * update README with flags * handle testing functions in php5.5 * de-dupe sequential code * slightly less code
- Loading branch information
Harry Bragg
authored
Sep 11, 2018
1 parent
cf27e85
commit f247888
Showing
19 changed files
with
414 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
<?php | ||
|
||
namespace Graze\ArrayMerger\ValueMerger; | ||
namespace Graze\ArrayMerger; | ||
|
||
interface ArrayMergerInterface | ||
{ | ||
/** | ||
* If 2 elements are both value arrays ['a','b','c'], etc. | ||
* This will append the second array onto the first. | ||
* | ||
* Example: | ||
* | ||
* ```php | ||
* merge(['a' => ['a','b','c']],['b' => ['d','e','f']]); | ||
* // ['a' => ['a','b','c','d','e','f']] | ||
* ``` | ||
* | ||
* If it is off, the first value will be replaced by the second | ||
*/ | ||
const FLAG_APPEND_VALUE_ARRAY = 1; | ||
|
||
/** | ||
* Merge the values from the subsequent set of arrays into the first array | ||
* | ||
* @param array $array1 | ||
* @param array ...$arrays | ||
* @param array $arrays multiple arrays to merge into array1 | ||
* | ||
* @return array | ||
*/ | ||
public function merge(array $array1, array ...$arrays); | ||
public function merge(array $array1, array $arrays = null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Graze\ArrayMerger; | ||
|
||
trait SequentialTrait | ||
{ | ||
/** | ||
* Check if the provided array is sequential or not | ||
* | ||
* @param array $array | ||
* | ||
* @return bool | ||
*/ | ||
protected function isSequential(array $array) | ||
{ | ||
if (!empty($array) && !array_key_exists(0, $array)) { | ||
return false; | ||
} | ||
return array_values($array) === $array; | ||
} | ||
|
||
/** | ||
* @param array $arrays Collection of arrays to check | ||
* | ||
* @return bool True if all the arrays are sequential | ||
*/ | ||
protected function areSequential(array $arrays) | ||
{ | ||
foreach ($arrays as $array) { | ||
if (!is_array($array) || !$this->isSequential($array)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.