return $index;
        } else {
            $index--;
        }
    }
}
print_r(stringAddTwo("12349"));
/*
 * #################################################################################################################
 * ########################################## By Reference vs By Value #############################################
 * #################################################################################################################
 */
echo "<h1>By Reference VS By Value</h1>";
//this will actually edit the passed variable in memory
function byRef(&$val)
{
    $val++;
    return 1;
}
//this will make a copy of the passed variable and edit it
function byVal($val)
{
    $val++;
    return 1;
}
$num = 3;
echo $num . "<br />";
byVal($num);
echo "After By Value: {$num}<br />";
byRef($num);
echo "After By Reference: {$num}<br />";
Example #2
0
<?php 
//func_get_args() example of byref and byval arguments
function byVal($arg)
{
    echo 'As passed     : ', var_export(func_get_args()), PHP_EOL;
    $arg = 'baz';
    echo 'After change  : ', var_export(func_get_args()), PHP_EOL;
}
function byRef(&$arg)
{
    echo 'As passed     : ', var_export(func_get_args()), PHP_EOL;
    $arg = 'baz';
    echo 'After change  : ', var_export(func_get_args()), PHP_EOL;
}
$arg = 'bar';
byVal($arg);
byRef($arg);
//The above example will output:
/*
As passed : array (
0 => 'bar',
)
After change : array (
0 => 'bar',
)
As passed : array (
0 => 'bar',
)
After change : array (
0 => 'baz',
)
Example #3
0
<?php

function byVal($arg)
{
    echo 'As passed     : ', var_export(func_get_args()), PHP_EOL;
    $arg = 'baz';
    echo 'After change  : ', var_export(func_get_args()), PHP_EOL;
}
function byRef(&$arg)
{
    echo 'As passed     : ', var_export(func_get_args()), PHP_EOL;
    $array = var_export(func_get_args());
    $array[0] = "xyzx";
    $array[1] = "yyyy";
    echo 'After change  : ', var_export(func_get_args()), PHP_EOL;
}
$arg1 = 'bar';
$arg2 = 'xyz';
byVal($arg1, $arg2);
byRef($arg1, $arg2);
echo "<br>OK:<br>{$arg1}";
print_r($arg1, $arg2);