Array_Map 使用多个本机回调? [英] Array_Map using multiple native callbacks?

查看:29
本文介绍了Array_Map 使用多个本机回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一个数组上运行 3 个本机函数:trimstrtouppermysql_real_escape_string.可以这样做吗?

I want to run 3 native functions on the same array: trim, strtoupper and mysql_real_escape_string. Can this be done?

像这样尝试将数组作为回调传递是行不通的:

Trying to pass an array as a callback like this isn't working:

$exclude = array_map(array('trim','strtoupper','mysql_real_escape_string'), explode("\n", variable_get('gs_stats_filter', 'googlebot')));

虽然这很好用,因为它只使用一个本机函数作为回调:

Although this works fine because it's only using one native function as the callback:

$exclude = array_map('trim', explode("\n", variable_get('gs_stats_filter', 'googlebot')));

推荐答案

你必须这样做:

$exclude = array_map(function($item) {
    return mysql_real_escape_string(strtoupper(trim($item)));
}, explode("\n", variable_get('gs_stats_filter', 'googlebot')));

这篇关于Array_Map 使用多个本机回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆