【发布时间】:2011-10-18 11:11:08
【问题描述】:
我对范围很熟悉,但没怎么用过。如果我通过在函数中使用 GLOBAL $variableName 知道变量名称是什么,我就知道如何在函数内部更改变量的值。
我正在编写一个传递 2 个参数的方法。第一个将接受一个包含字符串的数组,第二个将保存要执行的设置,例如用于加密和修剪以修剪空格的 md5。
有没有办法改变函数内第一个参数的值?或者您知道实现此目的的更好方法吗?
function _Edit($string, $rules)
{
#check if array
if(is_array($rules)!=TRUE)
{array_push($GLOBALS[debug], '<span class="error">_Edits second arguement must be an array</span>');}
if(is_array($string)!=TRUE)
{array_push($GLOBALS[debug], '<span class="error">_Edits first arguement must be an array</span>');}else
{
#loop through the strings
foreach ($string as $sk=>$sv)
{
#make changes based on rules
/* order of rules is important.
the changes will be made in the order the rules are sent */
foreach ($rules as $rv)
{
switch ($rv)
{
case 'md5':
//$string[$sk] = md5($sv);
//GLOBALS[$string][$sk] = md5($sv);
break;
}
}
}
}
}
【问题讨论】:
标签: php string function methods scope