Configuring array_map php array

Hi everyone, from time to time I use array_map to write recursive methods. eg

function stripSlashesRecursive( $value ){

    $value = is_array($value) ?
        array_map( 'stripSlashesRecursive', $value) :
    stripslashes( $value );
    return $value;
}

Question:

Let's say I want to put this function in a static class, how would I use the array_map array for the scope of the static method in the class, for example Sanitize :: stripSlashesRecursive (); I am sure it is easy, but I just can’t figure it out, I also looked at php.net.

+3
source share
3 answers

, array_map() usort(), . . - ( )

// 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 );
+16

array_map .

:

array('classname', 'methodname')


, :

array_map(array('stripSlashesRecursive', ''), $value);


. PHP: - , - .

+1
array_map( array('Sanitize', 'stripSlashesRecursive'), $value) ...
0

Source: https://habr.com/ru/post/1734321/


All Articles