本文整理汇总了PHP中swap函数的典型用法代码示例。如果您正苦于以下问题:PHP swap函数的具体用法?PHP swap怎么用?PHP swap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了swap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}*/
}
示例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]);
}
}
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
}