In PHP programming, we often encounter cell data problems with arrays, such as applying custom functions to each cell in the array.
One method is to iterate through the entire array, call the custom function on each cell, and replace the value of the corresponding cell in the original array with the return value. This is also the most common and simple method, which is not an example.
One way to do this is to callback the custom function via the Array_map function provided by PHP, which is also the recommended method.
Array_map--Functions The callback function to the cell of the given array
Array_map () returns an array that contains the cells of all cells in the arr1 after the callback function. The number of arguments accepted by callback should be consistent with the number of arrays passed to the Array_map () function.
Excerpts from a section of the PHP manual are briefly described below:
So, what if you're using the ARRAY_MAP function to callback internal methods in a PHP class?
Again, we can find a section of user-added instructions in the PHP manual:
If you are needto call a static method from Array_map, this is not work:
(If you want to recall a static method in the Array_map function, the following procedure is incorrect)
Thanks to the author for sharing, because the PHP manual for the Array_map function parameter description is really too simple, even the basic object method references are not mentioned.
Now, let's go to the topic we're talking about: what to do if you callback internal methods in a PHP class by using the Array_map function.
public static function _entities ($arg) {
$return = null;
if (Is_array ($arg)) {
This would neithor work under static call nor Classinstantiate
$return = Array_map (Array (self, ' _entities '), $arg);
This would work under both static call and Classinstantiate
$return = Array_map (Array (__class__, ' _entities '), $arg);
}else{
$return = Is_numeric ($arg)? $arg: Htmlspecialchars ($arg, ent_quotes);
}
Return $return
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.