Php Chinese network (www.php.cn) provides the most comprehensive basic tutorial on programming technology, introducing HTML, CSS, Javascript, Python, Java, Ruby, C, PHP, basic knowledge of MySQL and other programming languages. At the same time, this site also provides a large number of online instances, through which you can better learn programming... Reply: Since PHP was playing with closures, it was hard for everyone to jump to the fifth floor.
1. basics:
Define a function in one sentence and call it immediately
This is often done in JavaScript because variable pollution is intolerable. But how can this function be implemented in PHP? One feasible method is:
call_user_func(function(){ echo "hello,world";});
@ Chen has another solution.
pro()); //Error: Call to protected method A::pro() var_dump($this->pub());};$ext = $ext->bindTo($a);var_dump($ext());
scalar}.
"; }; $obj->scalar = "php bbb"; //$obj = (object) "php bbb"; callback($callback);
The C language tends to be an operator -->, and this PHP also does.
Add one: you can directly enter the URL in the PHP source code without comments (Black Magic ):
What do you mean when it comes to odd tricks? you can play games, but never use them in real projects. let's make two contributions:
Exchange two values:
List ($ B, $ a) = array ($ a, $ B );
$ A = array ($ B, $ B = $ a) [0]; of course, it is a magic BOM header. I don't know how many PHP beginners can't sleep well in the Quora list.
What are some cool PHP tricks?
Convert XML strings to Arrays
$xmlObj = simplexml_load_string($xmlStr);$xmlArr = json_decode(json_encode($xmlObj) , true);
1. stdClass ();
$obj = new stdClass;$obj->a = 1;$obj->b = 2;