Last active
July 23, 2016 06:14
-
-
Save mikemadisonweb/e67699872b721919e98d to your computer and use it in GitHub Desktop.
Helper functions
This file contains hidden or 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
<?php | |
/** | |
* Проверка элементов массива на дубликаты | |
* @param $array | |
* @return boolean | |
*/ | |
function arrayHasDuplicates($array) { | |
return count($array) !== count(array_unique($array)); | |
} |
This file contains hidden or 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
<?php | |
/** | |
* Преобразует любой мультиразмерный массив в одноразмерный | |
* @param array $array | |
* @param array $return | |
* @return array | |
*/ | |
private function flattenArray($array, $return = array()) { | |
for($x = 0; $x < count($array); $x++) { | |
if(is_array($array[$x])) { | |
$return = $this->flattenArray($array[$x], $return); | |
} | |
else { | |
if(isset($array[$x])) { | |
$return[] = $array[$x]; | |
} | |
} | |
} | |
return $return; | |
} | |
/** | |
* Преобразует любой мультиразмерный массив в одноразмерный | |
* @param array $array | |
* @return array | |
*/ | |
private function flattenArray(array $array) { | |
$return = array(); | |
array_walk_recursive($array, function($a,$b) use (&$return) { $return[$b] = $a; }); | |
return $return; | |
} |
This file contains hidden or 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
<?php | |
/** | |
* Вспомогательная функция, чтобы вставить элемент в ассоциативный массив в указанное место | |
* @param $array | |
* @param $key | |
* @param $val | |
* @param $index | |
* @return array | |
*/ | |
private function insertKeyValuePair($array, $key, $val, $index) | |
{ | |
$arrayEnd = array_splice($array, $index); | |
$arrayStart = array_splice($array, 0, $index); | |
return (array_merge($arrayStart, array($key=>$val), $arrayEnd )); | |
} |
This file contains hidden or 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
<?php | |
/** | |
* Убирает все null из массива | |
* @param $array | |
* @return array | |
*/ | |
private function notNullInArray($array) | |
{ | |
return array_values(array_filter($array, function($var){return !is_null($var);} )); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment