本文整理汇总了PHP中merge函数的典型用法代码示例。如果您正苦于以下问题:PHP merge函数的具体用法?PHP merge怎么用?PHP merge使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了merge函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: _headers
private function _headers()
{
// PHP mail() doesn't accept from and replyTo as parameters, so we need
// to add them here
$this->headers['From'] = $this->from;
$this->headers['Reply-To'] = merge($this->replyTo, $this->from);
// Everything needs to be converted to a newlined string
$return = '';
foreach ($this->headers as $header => $value) {
if ($value) {
$return .= $header . ': ' . $value . PHP_EOL;
}
}
// Since we can't do a backwards search, we'll make the string go backwards
$return = strrev($return);
$return = preg_replace('/' . PHP_EOL . '/', '', $return, 1);
return strrev($return);
}
开发者ID:CraigChilds94,项目名称:scaffold,代码行数:18,代码来源:standard.php
示例17: merger
function merger($list)
{
$len = count($list);
$chunks = array_chunk($list, 2);
$chunks = sort_item($chunks);
$container = array_chunk($chunks, 2);
while (true) {
foreach ($container as $k => $item) {
if (count($item) == 1) {
$container[$k] = $item[0];
} else {
$container[$k] = merge($item[0], $item[1]);
}
}
if (count($container[0]) == $len) {
break;
}
$container = array_chunk($container, 2);
}
return $container[0];
}
开发者ID:bloodynumen,项目名称:visualgo2php,代码行数:21,代码来源:mergesort.php
示例18: define
//.........这里部分代码省略.........
// Upper limit on item quantity.
if ($cart_items[$item_id]['quantity'] > $model->item_quantity_limit) {
$cart_items[$item_id]['quantity'] = $model->item_quantity_limit;
}
// Check product for pricing update?
$product = get("/products/{$cart_items[$item_id]['id']}", array('pricing' => array('roles' => $cart['account']['roles'], 'quantity' => $cart_items[$item_id]['quantity'] ?: 1)));
// Update pricing?
if ($product['pricing']) {
$cart_items[$item_id]['price'] = $product['price'];
}
}
// Remove item?
if ($data['items'][$item_id]['quantity'] <= 0) {
unset($cart_items[$item_id]);
}
}
$data['items'] = $cart_items;
}
// Removed coupon code?
if (isset($data['coupon_code']) && !$data['coupon_code']) {
// Remove coupon.
$data['discounts'] = $cart['discounts'];
unset($data['discounts']['coupon']);
} elseif ($data['coupon_code'] && $data['coupon_code'] != $cart['discount']['coupon']['code']) {
$discount = get("/discounts", array('code' => $data['coupon_code'], 'is_valid' => true));
if ($discount === false) {
$model->error('already used', 'coupon_code');
} else {
if (!$discount) {
$model->error('invalid', 'coupon_code');
}
}
// Remember code.
$data['coupon_code'] = $discount['code'];
// Update items from coupon.
foreach ((array) $discount['rules'] as $rule) {
if ($rule['add'] && $rule['product_id']) {
// Exists in cart?
$exists = false;
foreach ((array) $cart['items'] as $item_id => $item) {
if ($item['id'] == $rule['product_id']) {
$exists = $item_id;
break;
}
}
// Update item quantity?
if ($exists) {
put("{$cart}/items/{$exists}", array('quantity' => $rule['quantity']));
} else {
// Post new item to cart.
post("{$cart}/items", array('id' => $rule['product_id'], 'quantity' => $rule['quantity']));
}
}
}
$data['discounts'] = $cart['discounts'];
$data['discounts']['coupon'] = $discount;
} else {
// Don't update coupon code directly.
unset($data['coupon_code']);
}
// Extra discount updates.
if ($data['discounts']) {
foreach ((array) $data['discounts'] as $did => $discount) {
// Unset some discount details.
unset($data['discounts'][$did]['codes']);
unset($data['discounts'][$did]['codes_used']);
unset($data['discounts'][$did]['code_history']);
unset($data['discounts'][$did]['conditions']);
}
}
// Update order data? Merge.
if (isset($data['order']) && is_array($cart['order'])) {
if ($data['order']) {
if ($data['order']['shipping']) {
$data['order']['shipping'] = array_merge((array) $cart['order']['shipping'], (array) $data['order']['shipping']);
}
$data['order'] = $cart['order'] = array_merge($cart['order'], (array) $data['order']);
}
}
// Update shipping total?
if ($data['order'] || $data['items']) {
// @TODO: Make sure we don't need this.
//$data['shipping_total'] = Carts::get_shipping_total($cart);
}
// Use credit?
if ($data['credit_total']) {
// Validate.
$data['credit_total'] = Carts::get_credit_total(merge($cart, $data));
}
}
}, 'validate:order' => function ($order, $field, $params, $model) {
// Validate with orders collection.
$order[':validate'] = true;
$result = get("/orders", $order);
// Apply errors to cart model?
foreach ((array) $result['errors'] as $field => $error) {
$model->error($error, 'order', $field);
}
});
}
开发者ID:kfuchs,项目名称:fwdcommerce,代码行数:101,代码来源:Carts.php
示例19: unlink
unlink($outputFile);
unlink($over);
}
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) {
// Get the data
$imageData = $GLOBALS['HTTP_RAW_POST_DATA'];
$array_variable = get_variable($path_folder_save);
// $over = 'imagesVillagesBattles/over.png';
$over = $array_variable[1];
// $n = $array_variable[5];
// Remove the headers (data:,) part.
// A real application should use them according to needs such as to check image type
$filteredData = substr($imageData, strpos($imageData, ",") + 1);
// Need to decode before saving since the data we received is already base64 encoded
$unencodedData = base64_decode($filteredData);
$f = fopen($over, 'wb');
stream_filter_append($fh, 'convert.base64-decode');
// Do a lot of writing here. It will be automatically decoded from base64.
fclose($f);
file_put_contents($over, $unencodedData);
$size = getimagesize($over);
$w = $size[0];
$h = $size[1];
merge($w, $h);
write_comments();
}
?>
开发者ID:vincseize,项目名称:GDC,代码行数:27,代码来源:saveCanvas_OLD1.php
示例20: rl_split
require CLASS_DIR . 'options/split.php';
rl_split();
break;
case 'split_go':
if (!empty($options['disable_split'])) {
break;
}
require CLASS_DIR . 'options/split.php';
split_go();
break;
case 'merge':
if (!empty($options['disable_merge'])) {
break;
}
require CLASS_DIR . 'options/merge.php';
merge();
break;
case 'merge_go':
if (!empty($options['disable_merge'])) {
break;
}
require CLASS_DIR . 'options/merge.php';
merge_go();
break;
case 'rename':
if (!empty($options['disable_rename'])) {
break;
}
require CLASS_DIR . 'options/rename.php';
rl_rename();
break;
开发者ID:mewtutorial,项目名称:RapidTube,代码行数:31,代码来源:options.php
注:本文中的merge函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论