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.
, array_map() usort(), . . - ( )
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 );
array_map .
array_map
:
array('classname', 'methodname')
, :
array_map(array('stripSlashesRecursive', ''), $value);
. PHP: - , - .
array_map( array('Sanitize', 'stripSlashesRecursive'), $value) ...
Source: https://habr.com/ru/post/1734321/More articles:how to write this in linq to query an object? - c #WinForm chart management: resizing a chart while saving it to a file - c #Copy constructor? - c ++How can I use resources in aspx files? - c #Using SimpleDB (with SimpleSavant) with POCO / existing objects, not attributes on my classes - c #Iphone sdk image effects - iphoneMATLAB code packaging - oopjquery checkbox enable / disable radioobuttonlist - jquery'+' packaging or modular programming in Matlab: python import analog? - namespacesAm I breaking any “good php practice” in the following php array that deals with 3 (human) languages? - arraysAll Articles