php奇技淫巧 发表于 2016-08-12 | 分类于 php php闭包使用示例12345678910111213141516171819<?phpclass A{ public function handel(callable $callback) { call_user_func_array($callback, [1,2]); }}$obj = new A();$obj->handel(function ($a, $b){ echo $a . $b; }); XML字符串转数组12$xmlObj = simplexml_load_string($xmlStr);$xmlArr = json_decode(json_encode($xmlObj) , true); 12345// 论如何用最好的编程语言获得当天零点的UNIX时间戳echo strtotime("today midnight");//处理数据$_POST=array_map('addslashes',$_POST); A better way to do a lot of IF statements:1234567891011switch(TRUE){ case email_is_valid($email): // Do something. break; case username_is_valid($user): // Do stuff. break; case pass_too_short($pass) && pass_not_save($pass): // Other stuff. break;}