本文整理汇总了PHP中merge函数的典型用法代码示例。如果您正苦于以下问题:PHP merge函数的具体用法?PHP merge怎么用?PHP merge使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了merge函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: merge
function merge($part1, $part2, $part3 = null)
{
if ($part3 == null) {
echo "<h5>Merging " . json_encode($part1) . " and " . json_encode($part2) . " ===> Result: ";
$result = array();
while (count($part1) > 0 || count($part2) > 0) {
if (count($part1) > 0 && count($part2) > 0) {
if ($part1[0] < $part2[0]) {
array_push($result, array_shift($part1));
} else {
array_push($result, array_shift($part2));
}
} else {
if (count($part1) > 0) {
array_push($result, array_shift($part1));
} else {
array_push($result, array_shift($part2));
}
}
}
echo json_encode($result) . "</h5>";
return $result;
} else {
return merge(merge($part1, $part2), $part3);
}
}
示例2: creationConditions
public function creationConditions($conditionsDivers, $conditionsDons)
{
foreach ($conditionsDons as $nomCondition) {
$donsConditionnels[] = $nomCondition->getName();
}
$conditions = null;
$conditions[] = merge($conditionsDivers, $donsConditionnels);
return $conditions;
}
示例3: mergesort
function mergesort(&$shulie, $start, $end)
{
if ($start < $end) {
$middle = floor(($start + $end) / 2);
mergesort($shulie, $start, $middle);
mergesort($shulie, $middle + 1, $end);
merge($shulie, $start, $middle, $end);
}
}
示例4: get
function get($table, $fields = "*", $other = "")
{
if (is_array($fields)) {
$sql = "SELECT " . merge($fields) . " FROM " . $table . " " . $other;
} else {
$sql = "SELECT " . $fields . " FROM " . $table . " " . $other;
}
//echo $sql;
return conn()->query($sql)->fetchAll();
}
示例5: mergesort
function mergesort(&$lst, $a, $b)
{
if ($b - $a < 2) {
return;
}
$half = floor(($b + $a) / 2);
mergesort($lst, $a, $half);
mergesort($lst, $half, $b);
merge($lst, $a, $half, $b);
}
示例6: mergeSort
function mergeSort($array)
{
if (count($array) < 2) {
return $array;
}
$mid = count($array) / 2;
echo "<h5>Splitting " . json_encode($array) . " ===> Left: " . json_encode(array_slice($array, 0, $mid)) . " Right: " . json_encode(array_slice($array, $mid));
$right = mergeSort(array_slice($array, 0, $mid));
$left = mergeSort(array_slice($array, $mid));
return merge($left, $right);
}
示例7: merge_sort
function merge_sort($arr)
{
if (count($arr) <= 1) {
return $arr;
}
$left = array_slice($arr, 0, (int) (count($arr) / 2));
$right = array_slice($arr, (int) (count($arr) / 2));
$left = merge_sort($left);
$right = merge_sort($right);
$output = merge($left, $right);
return $output;
}
示例8: encode
/**
* Encodes a coordinate (latitude, longitude) into a GeoHash string
*
* @param double $latitude representing the latitude part of the coordinate set
* @param double $longitude representing the longitude part of the coordinate set
* @return string containing the GeoHash for the specified coordinates
*/
public static function encode($latitude, $longitude)
{
// Find precision (number of decimals)
$digits = self::_decimal($latitude, $longitude);
// Translate coordinates to binary strings
$latBinStr = self::_encode($latitude, -90.0, 90.0, $digits);
$lonBinStr = self::_encode($longitude, -180.0, 180.0, $digits);
// Merge the two binary strings
$binStr = merge($latBinStr, $lonBinStr);
// Calculate and return Geohash for 'binary' string
return self::_translate($binStr);
}
示例9: mergeSort
function mergeSort(array $arr)
{
$count = count($arr);
if ($count <= 1) {
return $arr;
}
$left = array_slice($arr, 0, (int) ($count / 2));
$right = array_slice($arr, (int) ($count / 2));
$left = mergeSort($left);
$right = mergeSort($right);
return merge($left, $right);
}
示例10: mergesort
function mergesort($arr)
{
if (count($arr) == 1) {
return $arr;
}
$mid = count($arr) / 2;
$left = array_slice($arr, 0, $mid);
$right = array_slice($arr, $mid);
$left = mergesort($left);
$right = mergesort($right);
return merge($left, $right);
}
示例11: merge_sort
function merge_sort($array)
{
if (count($array) == 1) {
return $array;
}
$middle = (int) (count($array) / 2);
$left = array_slice($array, 0, $middle);
$right = array_slice($array, $middle);
$left = merge_sort($left);
$right = merge_sort($right);
$return_array = merge($left, $right);
return $return_array;
}
示例12: get
/**
* The get() function returns reduced coeffs from the equation */
function get($eqn)
{
$res = split("=", $eqn);
if (!isset($res[1]) || isset($res[2])) {
return False;
}
$left = parse($res[0]);
$right = parse($res[1]);
if ($left === False || $right === False) {
return False;
}
return merge($left, $right);
}
示例13: merge
/**
* Merge two indexed arrays recursively.
*
* Usage example:
* {$set1 = [a => [b => c], x => y]}
* {$set2 = [a => [b => d]]}
* {$result = $set1|merge:$set2} # [a => [b => d], x => y]
*/
function merge($set1, $set2)
{
$merged = $set1;
if (is_array($set2) || $set2 instanceof ArrayIterator) {
foreach ($set2 as $key => &$value) {
if ((is_array($value) || $value instanceof ArrayIterator) && (is_array($merged[$key]) || $merged[$key] instanceof ArrayIterator)) {
$merged[$key] = merge($merged[$key], $value);
} elseif (isset($value) && !(is_array($merged[$key]) || $merged[$key] instanceof ArrayIterator)) {
$merged[$key] = $value;
}
}
}
return $merged;
}
示例14: merge_sort
function merge_sort($array_to_sort = '')
{
if (count($array_to_sort) == 1) {
return $array_to_sort;
} else {
$sp = count($array_to_sort) / 2;
$sp = floor($sp);
$left = array_slice($array_to_sort, 0, $sp);
$right = array_slice($array_to_sort, $sp);
$left = ms($left);
$right = ms($right);
$result = merge($left, $right);
return $result;
}
}
示例15: mergesort
function mergesort(&$a)
{
$cnt = count($a);
if ($cnt <= 1) {
return $a;
}
$half = $cnt / 2;
if ($cnt % 2 != 0) {
$half -= 0.5;
}
$a1 = array_slice($a, 0, $half);
$a2 = array_slice($a, $half, $cnt - $half);
mergesort($a1);
mergesort($a2);
$a = merge($a1, $a2);
}