note 109550 added to language.references.pass

From: Date: Fri, 27 Jul 2012 14:46:39 +0000
Subject: note 109550 added to language.references.pass
Groups: php.notes 
Request: Send a blank email to php-notes+get-189429@lists.php.net to get a copy of this message
<?php /* This function internally swaps the contents between two simple variables using 'passing by reference'. Some programming languages have such a swap function built in, but PHP seems to lack such a function. So, one was created to fill the need. It only handles simple, single variables, not arrays, but it is still a very handy tool to have. No value is actually returned by this function, but the contents of the indicated variables will be exchanged (swapped) after the call. */ // ------------------------------------------ // Demo call of the swap(...) function below. $a = 123.456; $b = 'abcDEF'; print "<pre>Define:\na = $a\nb = '$b'</pre>"; swap($a,$b); print "<pre>After swap(a,b):\na = '$a'\nb = $b</pre>"; // ------------------------------- function swap (&$arg1, &$arg2) { // Swap contents of indicated variables. $w=$arg1; $arg1=$arg2; $arg2=$w; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 67.244.128.14 ---- Manual Page -- http://www.php.net/manual/en/language.references.pass.php Edit -- https://master.php.net/note/edit/109550 Del: integrated -- https://master.php.net/note/delete/109550/integrated Del: useless -- https://master.php.net/note/delete/109550/useless Del: bad code -- https://master.php.net/note/delete/109550/bad+code Del: spam -- https://master.php.net/note/delete/109550/spam Del: non-english -- https://master.php.net/note/delete/109550/non-english Del: in docs -- https://master.php.net/note/delete/109550/in+docs Del: other reasons-- https://master.php.net/note/delete/109550 Reject -- https://master.php.net/note/reject/109550 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#189429) next »