• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Interesting swap without buffer

IvanStels Aug 20th, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. if(!function_exists('swap_int')) { function swap_int(&\$fv,&\$sv) { \$fv = (int)(((int)\$sv - (int)\$fv) + (\$sv = (int)\$fv)); } } //поменять числа местами без буфера
2.
3. if(!function_exists('swap_arr')) { function swap_arr(&\$fa,&\$sa) { \$fa = array_diff(array_merge(\$sa,(\$sa = \$fa)),\$fa); } } //поменять массивы местами без буфера
4.
5. if(!function_exists('swap_str')) { function swap_str(&\$fs,&\$ss) {
6.   \$fs = str_split(\$fs);
7.   \$fs = implode(array_merge(str_split(\$ss),(\$ss = \$fs)));
8.   \$ss = implode(\$ss);
9.   \$fs = str_replace(\$ss,'',\$fs);
10. } } //поменять строки местами без буфера
11.
12. if(!function_exists('swap_values')) { function swap_values(&\$var_1,&\$var_2) {
13.    if(gettype(\$var_1) == gettype(\$var_2)) {
14.
15.        switch(gettype(\$var_1)):
16.
17.            case 'string': swap_str(\$var_1,\$var_2); break;
18.
19.            case 'integer': swap_int(\$var_1,\$var_2); break;
20.
21.            case 'array': swap_arr(\$var_1,\$var_2); break;
22.
23.            default: return gettype(\$var_1);
24.
25.        endswitch;
26.
27.    } else return false;
28.
29.    return true;
30. } }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?