Exemple #1
0
function main()
{
    $a = array();
    byref($a[][0]);
    var_dump($a);
    byval($a[][0]);
}
Exemple #2
0
<?php

$a = 4;
$b = 5;
$c = byval($a, $b);
$f = 4;
$g = 5;
$h = byref($f, $g);
echo "a={$a}<br>";
echo "b={$b}<br>";
echo "c={$c}<br>";
echo "f={$f}<br>";
echo "g={$g}<br>";
echo "h={$h}<br>";
function byref(&$a1, $b1)
{
    $a1 += $b1;
    return $a1;
}
function byval($a2, $b2)
{
    $a2 += $b2;
    return $a2;
}
// get host name from URL
preg_match('@^(?:http://)?([^/]+)@i', "http://www.php.net/index.html", $matches);
$host = $matches[1];
// get last two segments of host name
preg_match('/[^.]+\\.[^.]+$/', $host, $matches);
echo "domain name is: {$matches[0]}\n";
    $c->v = 'changed';
}
var_dump($z);
echo "Test return values by reference\n";
function &byref()
{
    static $foo;
    $foo++;
    echo "{$foo}\n";
    return $foo;
}
$bar = byref();
$bar++;
byref();
$bar =& byref();
$bar++;
byref();
echo "Test return values getting copied\n";
function copying()
{
    static $foo;
    $foo[] = "asdf";
    var_dump($foo);
    return $foo;
}
$bar = copying();
$bar[] = 22;
copying();
$bar =& copying();
$bar[] = 23;
copying();
Exemple #4
0
<?php

/**
 * Created by PhpStorm.
 * User: JoeL
 * Date: 9/22/2015
 * Time: 8:54 PM
 */
function byref(&$val)
{
    $val += 1;
    return 1;
}
function byval($val)
{
    $val += 1;
    return 1;
}
$num = 3;
echo "Original number " . $num . "<br>";
byval($num);
echo "After By Value " . $num . "<br>";
byref($num);
echo "After By Reference " . $num . "<br>";
byval($num);
echo "After By Value again " . $num . "<br>";