当前位置: 首页>>代码示例>>PHP>>正文


PHP merge函数代码示例

本文整理汇总了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);
    }
}
开发者ID:Kolahzary,项目名称:AlgorithmsImplementation,代码行数:26,代码来源:MergeSort-3parts.php

示例2: creationConditions

 public function creationConditions($conditionsDivers, $conditionsDons)
 {
     foreach ($conditionsDons as $nomCondition) {
         $donsConditionnels[] = $nomCondition->getName();
     }
     $conditions = null;
     $conditions[] = merge($conditionsDivers, $donsConditionnels);
     return $conditions;
 }
开发者ID:Malgorne,项目名称:LORDFUMBLE,代码行数:9,代码来源:DonToConditionsTransformer.php

示例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);
    }
}
开发者ID:HustC,项目名称:husterC,代码行数:9,代码来源:sigh.php

示例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();
}
开发者ID:phDirectory,项目名称:phdirectory,代码行数:10,代码来源:helper.php

示例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);
}
开发者ID:handydannu,项目名称:DESKTOP_APPS,代码行数:10,代码来源:mergesort.php

示例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);
}
开发者ID:Kolahzary,项目名称:AlgorithmsImplementation,代码行数:11,代码来源:MergeSort.php

示例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;
}
开发者ID:eltonoliver,项目名称:Algorithms,代码行数:12,代码来源:mergesort.php

示例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);
 }
开发者ID:janpoo,项目名称:geohash,代码行数:19,代码来源:GeoHash.php

示例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);
}
开发者ID:CaptainSharf,项目名称:SSAD_Project,代码行数:12,代码来源:sortingAlgos.php

示例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);
}
开发者ID:pombredanne,项目名称:fuzzer-fat-fingers,代码行数:12,代码来源:Merge.php

示例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;
}
开发者ID:sifxtreme,项目名称:php-coding-exercises,代码行数:13,代码来源:merge_sort.php

示例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);
}
开发者ID:ale-roy,项目名称:comp,代码行数:15,代码来源:parse.php

示例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;
}
开发者ID:kfuchs,项目名称:fwdcommerce,代码行数:22,代码来源:merge.php

示例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;
    }
}
开发者ID:nik6018,项目名称:Algorithms,代码行数:15,代码来源:sort_algorithms.php

示例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);
}
开发者ID:jhogan,项目名称:nplay,代码行数:16,代码来源:sorttest.php


注:本文中的merge函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。