我试图理解为什么这个功能不起作用.有人教育我发生了什么吗?
function API() { $seed = str_split(md5(rand(0000000,9999999))); $rand = array_rand($seed, 10); $convert = array_map(function($n){ global $seed; return $seed[$n]; },$rand); $var1 = implode('',$convert); $seed = str_split(md5(rand(0000000,9999999))); $rand = array_rand($seed, 10); $convert = array_map(function($n){ global $seed; return $seed[$n]; },$rand); $var2 = implode('',$convert); $seed = str_split(md5(rand(0000000,9999999))); $rand = array_rand($seed, 10); $convert = array_map(function($n){ global $seed; return $seed[$n]; },$rand); $var3 = implode('',$convert); $NewRecordLocatorID = $var1 . '-' . $var2 . '-' . $var3; return $NewRecordLocatorID; }
此功能仅返回 --
只是回应功能之外的价值?这需要在课堂上吗?
$seed = str_split(md5(rand(0000000,9999999))); $rand = array_rand($seed, 10); $convert = array_map(function($n){ global $seed; return $seed[$n]; },$rand); $var1 = implode('',$convert); $seed = str_split(md5(rand(0000000,9999999))); $rand = array_rand($seed, 10); $convert = array_map(function($n){ global $seed; return $seed[$n]; },$rand); $var2 = implode('',$convert); $seed = str_split(md5(rand(0000000,9999999))); $rand = array_rand($seed, 10); $convert = array_map(function($n){ global $seed; return $seed[$n]; },$rand); $var3 = implode('',$convert); $NewRecordLocatorID = $var1 . '-' . $var2 . '-' . $var3; echo $NewRecordLocatorID;
以上将返回1d0f09fd36-1e656c979d-3468a68fea
所需的结果.
这是因为你打电话的方式global
.改变这些:
$convert = array_map(function($n){ global $seed; return $seed[$n]; },$rand);
对此:
$convert = array_map(function($n) use ($seed){ return $seed[$n]; },$rand);
瞧,它有效.