array_map PHP的设置范围 [英] setting scope of array_map php
问题描述
嘿所有,我使用array_map不时编写递归方法。例如:
hey all, i use array_map from time to time to write recursive methods. for example
function stripSlashesRecursive( $value ){
$value = is_array($value) ?
array_map( 'stripSlashesRecursive', $value) :
stripslashes( $value );
return $value;
}
问:
说我想把这个功能在静态类中,我如何使用array_map回到静态方法的范围像消毒:: stripSlashesRecursive类();
我敢肯定,这是简单,但我只是不能figgure出来,看着php.net为好。
say i wanna put this function in a static class, how would i use array_map back to the scope of the static method in the class like Sanitize::stripSlashesRecursive(); Im sure this is simple but i just cant figgure it out, looked at php.net as well.
推荐答案
在使用一个类的方法,比如的功能的回调array_map()
和 usort()
,你必须发送回调的二值数组。第二值始终方法作为字符串的名称。第一个值是上下文(类名或对象)
When using a class method as a callback for functions like array_map()
and usort()
, you have to send the callback as two-value array. The 2nd value is always the name of the method as a string. The 1st value is the context (class name or object)
// Static outside of class context
array_map( array( 'ClassName', 'methodName' ), $array );
// Static inside class context
array_map( array( __CLASS__, 'methodName' ), $array );
// Non-static outside of object context
array_map( array( $object, 'methodName' ), $array );
// Non-static inside of object context
array_map( array( $this, 'methodName' ), $array );
这篇关于array_map PHP的设置范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!