A quick question.
Is it possible to declare the callback function inline, in php? For example,
array_filter($input_array, "function($item) { $item['state'] != 0 }")
A quick question.
Is it possible to declare the callback function inline, in php? For example,
array_filter($input_array, "function($item) { $item['state'] != 0 }")
Yes, after php 5.3, you could use anonymous function.
array_filter($input_array, function($item) { return $item['state'] != 0; });
Sure it calls anonymous functions:
array_filter($input_array, function($item) {
return $item['state'] != 0;
});
array_filter($input_array, function($item) {
return $item['state'] != 0;
});
This functionality is available from 5.3 or > version of php. In 5.4> version will support $this in inline Anonymous Functions
link for php callback > How do I implement a callback in PHP?
with create_function? ex:
$result = array_filter($array, create_function('$a','return preg_match("#\S#", $a);'));
© 2022 - 2024 — McMap. All rights reserved.