本文整理汇总了PHP中swap函数的典型用法代码示例。如果您正苦于以下问题:PHP swap函数的具体用法?PHP swap怎么用?PHP swap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了swap函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: itemuse
function itemuse(&$theitem)
{
if (eval(__MAGIC__)) {
return $___RET_VALUE;
}
eval(import_module('sys', 'player', 'itemmain', 'logger'));
$itm =& $theitem['itm'];
$itmk =& $theitem['itmk'];
$itme =& $theitem['itme'];
$itms =& $theitem['itms'];
$itmsk =& $theitem['itmsk'];
if (strpos($itmk, 'A') === 0) {
$eqp = 'art';
$noeqp = '';
if ($noeqp && strpos(${$eqp . 'k'}, $noeqp) === 0 || !${$eqp . 's'}) {
${$eqp} = $itm;
${$eqp . 'k'} = $itmk;
${$eqp . 'e'} = $itme;
${$eqp . 's'} = $itms;
${$eqp . 'sk'} = $itmsk;
$log .= "装备了<span class=\"yellow\">{$itm}</span>。<br>";
$itm = $itmk = $itmsk = '';
$itme = $itms = 0;
} else {
swap(${$eqp}, $itm);
swap(${$eqp . 'k'}, $itmk);
swap(${$eqp . 'e'}, $itme);
swap(${$eqp . 's'}, $itms);
swap(${$eqp . 'sk'}, $itmsk);
$log .= "卸下了<span class=\"red\">{$itm}</span>,装备了<span class=\"yellow\">{${$eqp}}</span>。<br>";
}
return;
}
$chprocess($theitem);
}
开发者ID:winddramon,项目名称:dts,代码行数:35,代码来源:main.php
示例2: selection_sort
function selection_sort($arr)
{
$last = count($arr) - 1;
$time_start = microtime(true);
for ($i = 0; $i < count($arr) - $i; $i++) {
$min_idx = $i;
$max_idx = $last - $i;
for ($j = $i; $j < count($arr) - $i; $j++) {
if ($arr[$min_idx] > $arr[$j]) {
$min_idx = $j;
}
if ($arr[$max_idx] < $arr[$j]) {
$max_idx = $j;
}
}
swap($i, $min_idx, $arr);
// swap the minimun to the head of the array;
if ($i == $max_idx) {
$max_idx = $min_idx;
}
swap($last - $i, $max_idx, $arr);
// swap the maximum to the end of the array;
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "<font color='red'>The sort took: " . $time . " second(s).</font><br>";
echo "<b>Sorted Array: <br></b>";
var_dump($arr);
}
开发者ID:popsun007,项目名称:PHP_selection_sort,代码行数:29,代码来源:selection_sort.php
示例3: insertion_sort
function insertion_sort($arr)
{
//Base case
$first = $arr[0];
$second = $arr[1];
if ($arr[1] < $arr[0]) {
swap($first, $second);
$arr[0] = $first;
$arr[1] = $second;
}
//Induction Hypothesis add 2
foreach ($arr as $keys => $values) {
//keys + 2 is current key
for ($i = $keys + 2; $i < count($arr); $i++) {
for ($j = $keys + 2; $j == 0; $j--) {
if ($arr[$keys + 2] < $arr[$j]) {
// swap variables
// swap($arr[$j],$arr[$keys+2]);
$temp = $arr[$j];
$arr[$j] = $arr[$keys + 2];
$arr[$keys + 2] = $temp;
}
}
}
}
var_dump($arr);
}
开发者ID:jreyles,项目名称:lamp-stack,代码行数:27,代码来源:insertion_sort.php
示例4: swap3
function swap3($s, $rr)
{
$s = explode("\\\\", $s);
foreach ($rr as $r) {
$s = array_map(function ($s) use($r) {
return swap($s, "\\{$r}", $r);
}, $s);
}
return implode("\\\\", $s);
}
开发者ID:NasalMusician,项目名称:Pantheum,代码行数:10,代码来源:string.php
示例5: test_prune_doesnt_execute_if_configuration_directory_doesnt_exist
public function test_prune_doesnt_execute_if_configuration_directory_doesnt_exist()
{
$files = Mockery::mock(Filesystem::class . '[exists]');
swap(Filesystem::class, $files);
$files->shouldReceive('exists')->with(VALET_HOME_PATH . '/config.json')->andReturn(false);
$config = Mockery::mock(Configuration::class . '[read,write]', [$files]);
$config->shouldReceive('read')->never();
$config->shouldReceive('write')->never();
$config->prune();
}
开发者ID:jmarcher,项目名称:valet-linux,代码行数:10,代码来源:ConfigurationTest.php
示例6: test_caddy_daemon_is_placed_in_correct_location
public function test_caddy_daemon_is_placed_in_correct_location()
{
$files = Mockery::mock(Filesystem::class . '[put]');
swap(Filesystem::class, $files);
$caddy = resolve(Caddy::class);
$files->shouldReceive('put')->andReturnUsing(function ($path, $contents) use($caddy) {
$this->assertEquals($caddy->daemonPath, $path);
$this->assertTrue(strpos($contents, VALET_HOME_PATH) !== false);
});
$caddy->installCaddyDaemon();
}
开发者ID:larawhale,项目名称:valet4win,代码行数:11,代码来源:CaddyTest.php
示例7: minHeapFixup
function minHeapFixup(array &$a, $i)
{
for ($j = (int) (($i - 1) / 2); $j >= 0 && $i != 0 && $a[$i] < $a[$j]; $i = $j, $j = (int) (($i - 1) / 2)) {
swap($a[$i], $a[$j]);
}
/*$j = (int)(($i-1)/2);
while ( $j>=0 && $i!=0 && $a[$i]<$a[$j] ) {
swap($a[$i], $a[$j]);
$i=$j; $j=(int)(($i-1)/2);
}*/
}
开发者ID:silentred,项目名称:learning-path,代码行数:11,代码来源:heap_sort.php
示例8: selectSort
function selectSort(&$arr)
{
$len = count($arr);
for ($i = 0; $i < $len; $i++) {
$pos = selectMin($arr, $i, $len);
if ($i != $pos) {
// 找到的最小数不是第一个数时,交换这两个数
swap($arr[$i], $arr[$pos]);
}
}
}
开发者ID:zhangta,项目名称:hades,代码行数:11,代码来源:selectSort.php
示例9: partition
function partition(&$array, $left, $right)
{
$k = $left - 1;
$pivot = $array[$right];
for ($i = $left; $i <= $right; $i++) {
if ($array[$i] <= $pivot) {
$k += 1;
swap($array, $k, $i);
}
}
return $k;
}
开发者ID:tuty,项目名称:IT-Talents,代码行数:12,代码来源:task_02.php
示例10: cook65
function cook65($b65, $fm, $to)
{
$pos = $fm + $to;
if ($pos < 0 || $pos > 64 || $fm == $pos) {
return $b65;
}
if ($fm > $pos) {
@swap($fm, $pos);
}
$b65 = @substr($b65, 0, $fm) . @substr($b65, $pos, 1) . @substr($b65, $fm + 1, $pos - $fm - 1) . @substr($b65, $fm, 1) . @substr($b65, $pos + 1);
return @substr($b65, $pos) . @substr($b65, 0, $pos);
}
开发者ID:abdeljawwad,项目名称:sedr,代码行数:12,代码来源:inc.func.enc65.php
示例11: permutation
function permutation($str, $i, $n)
{
if ($i == $n) {
print $str . "<br />";
} else {
for ($j = $i; $j < $n; $j++) {
$str = swap($str, $i, $j);
permutation($str, $i + 1, $n);
$str = swap($str, $i, $j);
}
}
}
开发者ID:Steadroy,项目名称:algorithm,代码行数:12,代码来源:permutation-of-string.php
示例12: bubbleSort
function bubbleSort(&$array)
{
do {
$swapped = false;
for ($i = 0, $c = count($array) - 1; $i < $c; $i++) {
if ($array[$i] > $array[$i + 1]) {
swap($array, $i);
$swapped = true;
}
}
} while ($swapped);
}
开发者ID:tuty,项目名称:IT-Talents,代码行数:12,代码来源:task_01.php
示例13: permute
/**
* Returns the Permutations of a String
*/
function permute($in, $startPos, $endPos)
{
if (strlen($in) == 1 || $startPos == $endPos) {
print $in . "\n";
return $in;
} else {
for ($a = $startPos; $a < $endPos; $a++) {
$in = swap($in, $startPos, $a);
permute($in, $startPos + 1, $endPos);
}
}
}
开发者ID:nickysemenza,项目名称:algorithms,代码行数:15,代码来源:string_permutations.php
示例14: test_symlink_creates_symlink_to_given_path
public function test_symlink_creates_symlink_to_given_path()
{
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('ensureDirExists')->once()->with(VALET_HOME_PATH . '/Sites', user());
$config = Mockery::mock(Configuration::class);
$config->shouldReceive('prependPath')->once()->with(VALET_HOME_PATH . '/Sites');
$files->shouldReceive('symlinkAsUser')->once()->with('target', VALET_HOME_PATH . '/Sites/link');
swap(Filesystem::class, $files);
swap(Configuration::class, $config);
$linkPath = resolve(Site::class)->link('target', 'link');
$this->assertEquals(VALET_HOME_PATH . '/Sites/link', $linkPath);
}
开发者ID:larawhale,项目名称:valet4win,代码行数:12,代码来源:SiteTest.php
示例15: getclub
function getclub($who, &$c1, &$c2, &$c3)
{
global $db, $tablepre, $starttime, $validtime;
$result = $db->query("SELECT gid FROM {$tablepre}winners ORDER BY gid desc LIMIT 1");
$t = $db->fetch_array($result);
$curgid = $t['gid'] + 1;
$result = $db->query("SELECT uid FROM {$tablepre}users WHERE username='{$who}'");
$t = $db->fetch_array($result);
$curuid = $t['uid'] + 2;
$result = $db->query("SELECT pid FROM {$tablepre}players WHERE name='{$who}' AND type=0");
$t = $db->fetch_array($result);
$curpid = $result['pid'] + 3;
$c1 = calc(12347, 10007, $curgid, $curuid, $curpid, $starttime, $validtime);
$c1 %= 6;
if ($c1 == 0) {
$c1 = 9;
}
//超能称号为9号
$delt = 0;
while ($delt <= 30) {
$c2 = calc(10009, 7789 + $delt, $curgid, $curuid, $curpid, $starttime, $validtime);
$c2 %= 5;
$c2++;
//第二个称号不允许超能
if ($c1 != $c2) {
break;
}
$delt++;
}
if ($delt > 30) {
if ($c1 == 1) {
$c2 = 2;
} else {
$c2 = 1;
}
}
$c3 = calc(11131, 6397, $curgid, $curuid, $curpid, $starttime, $validtime);
$clubid = array(6, 7, 8, 99, 10, 11, 13, 14, 16, 18, 19, 7, 99, 13, 14, 18, 6, 19, 13, 14, 18);
$c3 %= 21;
$c3 = $clubid[$c3];
if ($c1 == $c3 || $c2 == $c3) {
$c3 = 99;
}
if ($c1 > $c2) {
swap($c1, $c2);
}
if ($c1 > $c3) {
swap($c1, $c3);
}
if ($c2 > $c3) {
swap($c2, $c3);
}
}
开发者ID:jiangtiandao,项目名称:phpdts,代码行数:53,代码来源:clubslct.func.php
示例16: permute
function permute($str, $i, $n)
{
if ($i == $n) {
print "{$str}\n";
} else {
for ($j = $i; $j < $n; $j++) {
swap($str, $i, $j);
permute($str, $i + 1, $n);
swap($str, $i, $j);
// backtrack.
}
}
}
开发者ID:eltonoliver,项目名称:Algorithms,代码行数:13,代码来源:string_permutations.php
示例17: partition
function partition($arr, $left, $right, $pivot)
{
$pivValue = $arr[$pivot];
swap($arr, $pivot, $right);
$storePos = $left;
for ($i = $left; $i < $right; $i++) {
if ($arr[$i] < $pivValue) {
swap($arr, $i, $storePos);
$storePos++;
}
}
swap($list, $storePos, $right);
return $storePos;
}
开发者ID:nicksc423,项目名称:Algorithms,代码行数:14,代码来源:kthLargest.php
示例18: quicksort
function quicksort(&$arr, $st, $end)
{
if ($st == $end) {
return;
}
$sep = $st;
for ($i = $st + 1; $i < $end; $i++) {
if ($arr[$i] < $arr[$st]) {
swap($arr, ++$sep, $i);
}
}
swap($arr, $st, $sep);
quicksort($arr, $st, $sep);
quicksort($arr, $sep + 1, $end);
}
开发者ID:antonini,项目名称:quicksort,代码行数:15,代码来源:quicksort.php
示例19: partition
function partition(array &$arr, $pivotIndex, $startIndex = 0, $stopIndex = null)
{
$stopIndex = $stopIndex !== null ? $stopIndex : count($arr) - 1;
swap($arr[$startIndex], $arr[$pivotIndex]);
$pivot = $arr[$startIndex];
$i = $startIndex + 1;
for ($j = $startIndex; $j <= $stopIndex && $i <= $stopIndex; $j++) {
if ((double) $arr[$j] < (double) $pivot) {
swap($arr[$j], $arr[$i]);
$i++;
}
}
swap($arr[$startIndex], $arr[$i - 1]);
return $i - 1;
}
开发者ID:vutung2311,项目名称:SnippetCode,代码行数:15,代码来源:quickSort.php
示例20: partition
function partition(&$A, $p, $r)
{
$pviot = $A[$r];
$j = $p;
$i = $p - 1;
while ($j < $r) {
if ($A[$j] < $pviot) {
$i++;
swap($A[$i], $A[$j]);
}
$j++;
}
$i = $i + 1;
swap($A[$i], $A[$r]);
return $i;
}
开发者ID:ironxu,项目名称:aboutme,代码行数:16,代码来源:e.php
注:本文中的swap函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论