本文整理汇总了PHP中map_deep函数的典型用法代码示例。如果您正苦于以下问题:PHP map_deep函数的具体用法?PHP map_deep怎么用?PHP map_deep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了map_deep函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_map_deep_should_map_each_object_property_of_an_object
function test_map_deep_should_map_each_object_property_of_an_object() {
$this->assertEquals( (object)array( 'var0' => 'ababa', 'var1' => (object)array( 'xbaba' ) ),
map_deep( array( $this, 'append_baba' ), (object)array( 'var0' => 'a', 'var1' => (object)array( 'x' ) ) ) );
}
示例2: wp_kses_post_deep
/**
* Navigates through an array, object, or scalar, and sanitizes content for
* allowed HTML tags for post content.
*
* @since 4.4.2
*
* @param mixed $value The array or string to filter.
* @return mixed $value The filtered content.
*/
function wp_kses_post_deep($data)
{
return map_deep($data, 'wp_kses_post');
}
示例3: map_deep
/**
* Maps a function to all non-iterable elements of an array or an object.
*
* This is similar to `array_walk_recursive()` but acts upon objects too.
*
* @since 4.4.0
*
* @param mixed $value The array, object, or scalar.
* @param callable $callback The function to map onto $value.
* @return The value with the callback applied to all non-arrays and non-objects inside it.
*/
function map_deep($value, $callback)
{
if (is_array($value) || is_object($value)) {
foreach ($value as &$item) {
$item = map_deep($item, $callback);
}
return $value;
} else {
return call_user_func($callback, $value);
}
}
示例4: map_deep
/**
* Maps a function to all non-iterable elements of an array or an object.
*
* This is similar to `array_walk_recursive()` but acts upon objects too.
*
* @since 4.4.0
*
* @param mixed $value The array, object, or scalar.
* @param callable $callback The function to map onto $value.
* @return The value with the callback applied to all non-arrays and non-objects inside it.
*/
function map_deep( $value, $callback ) {
if ( is_array( $value ) ) {
foreach ( $value as $index => $item ) {
$value[ $index ] = map_deep( $item, $callback );
}
} elseif ( is_object( $value ) ) {
$object_vars = get_object_vars( $value );
foreach ( $object_vars as $property_name => $property_value ) {
$value->$property_name = map_deep( $property_value, $callback );
}
} else {
$value = call_user_func( $callback, $value );
}
return $value;
}
示例5: test_map_deep_should_map_array_elements_passed_by_reference
/**
* @ticket 35058
*/
public function test_map_deep_should_map_array_elements_passed_by_reference()
{
$array_a = array('var0' => 'a');
$array_b = array('var0' => &$array_a['var0'], 'var1' => 'x');
$this->assertEquals(array('var0' => 'ababa', 'var1' => 'xbaba'), map_deep($array_b, array($this, 'append_baba')));
}
示例6: gv_map_deep
/**
* Maps a function to all non-iterable elements of an array or an object.
*
* @see map_deep() This is an alias of the WP core function `map_deep()`, added in 4.4. Here for legacy purposes.
* @since 1.16.3
*
* @param mixed $value The array, object, or scalar.
* @param callable $callback The function to map onto $value.
*
* @return mixed The value with the callback applied to all non-arrays and non-objects inside it.
*/
function gv_map_deep($value, $callback)
{
// Use the original function, if exists.
// Requires WP 4.4+
if (function_exists('map_deep')) {
return map_deep($value, $callback);
}
// Exact copy of map_deep() code below:
if (is_array($value)) {
foreach ($value as $index => $item) {
$value[$index] = gv_map_deep($item, $callback);
}
} elseif (is_object($value)) {
$object_vars = get_object_vars($value);
foreach ($object_vars as $property_name => $property_value) {
$value->{$property_name} = gv_map_deep($property_value, $callback);
}
} else {
$value = call_user_func($callback, $value);
}
return $value;
}
示例7: update_term_meta
/**
* Sanitizes and saves term meta data when a term is altered.
*
* @since 2.7.0
*
* @param int $term_id Term ID.
* @param int $tt_id Term Taxonomy ID.
* @param string $taxonomy Taxonomy Slug
* @return void Early on AJAX call.
*/
public function update_term_meta($term_id, $tt_id, $taxonomy = '')
{
if (defined('DOING_AJAX') && DOING_AJAX) {
return;
}
//* Check again against ambiguous injection.
if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'update-tag_' . $term_id)) {
$data = isset($_POST['autodescription-meta']) ? (array) map_deep($_POST['autodescription-meta'], 'esc_attr') : array();
$data = wp_parse_args($data, $this->get_term_meta_defaults());
update_term_meta($term_id, THE_SEO_FRAMEWORK_TERM_OPTIONS, $data);
}
}