小编Adi*_*are的帖子

PHP 7.2 - 如何在字符串中包含函数体时动态创建匿名函数

当我在字符串中有函数体时,如何动态创建匿名函数.

例如

$user = "John Doe";
$body = "echo 'Hello' . $user;";

$myFunct = function($user) {$body}; // How do I have function body here from string.

$myFunct($user);
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激.

PS我正在寻找替代create_function()功能,这在PHP的早期版本中是有的.就像在create_function()中我们可以将函数体作为字符串传递一样,我想在字符串变量中定义匿名函数的主体.

php anonymous-function php-7.2

11
推荐指数
1
解决办法
683
查看次数

请解释为什么PHP switch case始终在此代码中执行case 0

有人可以解释为什么在下面的代码中永远不会达到"a"的情况以及为什么它总是会执行0

switch ("a") {
case 0:
    echo "0";
    break;
case "a": // never reached because "a" is already matched with 0
    echo "a";
    break;
}
Run Code Online (Sandbox Code Playgroud)

php switch-statement

5
推荐指数
1
解决办法
1187
查看次数

需要正则表达式帮助json字符串

我想从下面给出的数据中提取值 - 屏幕名称,名称,ID,配置文件图片URL:

[{"id_str":"135977294","description":"4TechCareers is the \u2018insiders\u2019 view of TechCareers.com. Join the Tech job search conversation. @JenGreenfield is the voice for our questions, tips, articles.","follow_request_sent":null,"profile_use_background_image":false,"screen_name":"4TechCareers","status":{"id_str":"15744807225790464","place":null,"coordinates":null,"favorited":false,"in_reply_to_screen_name":null,"in_reply_to_status_id_str":null,"source":"\u003Ca href=\"http:\/\/www.hootsuite.com\" rel=\"nofollow\"\u003EHootSuite\u003C\/a\u003E","contributors":null,"retweet_count":0,"in_reply_to_user_id_str":null,"retweeted":false,"created_at":"Fri Dec 17 12:27:09 +0000 2010","in_reply_to_status_id":null,"geo":null,"in_reply_to_user_id":null,"id":15744807225790464,"truncated":false,"text":"E.U. Deepens Investigation Into Google - European authorities have accepted two additional complaints from Germany, ... http:\/\/ow.ly\/1auOcZ"},"favourites_count":0,"profile_background_color":"1b3859","statuses_count":1215,"profile_background_image_url":"http:\/\/s.twimg.com\/a\/1291661299\/images\/themes\/theme1\/bg.png","url":"http:\/\/www.techcareers.com","listed_count":6,"profile_text_color":"333333","followers_count":238,"location":"","profile_sidebar_fill_color":"f7d35e","lang":"en","verified":false,"profile_background_tile":false,"time_zone":"Quito","created_at":"Thu Apr 22 18:05:29 +0000 2010","protected":false,"friends_count":967,"name":"4TechCareers","is_translator":false,"show_all_inline_media":false,"geo_enabled":false,"profile_link_color":"123a6b","id":135977294,"contributors_enabled":false,"following":null,"notifications":null,"utc_offset":-18000,"profile_sidebar_border_color":"e3bc0c","profile_image_url":"http:\/\/a3.twimg.com\/profile_images\/843661363\/TechCareers_bigger_normal.jpg"},{"id_str":"46620750","description":"50% Sharemilker dairy farmer own 550 cows and 400 youngstock and beef, Passion for grass based milk and beef production","follow_request_sent":null,"following":null,"profile_use_background_image":true,"status":{"id_str":"15644729492381696","favorited":false,"created_at":"Fri Dec 17 05:49:28 +0000 2010","place":null,"in_reply_to_screen_name":null,"in_reply_to_status_id_str":null,"source":"web","contributors":null,"retweet_count":0,"in_reply_to_user_id_str":null,"geo":null,"retweeted":false,"in_reply_to_status_id":null,"in_reply_to_user_id":null,"id":15644729492381696,"coordinates":null,"truncated":false,"text":"a cold beer after …
Run Code Online (Sandbox Code Playgroud)

php regex json

1
推荐指数
1
解决办法
198
查看次数