聘我网

新概念招聘3.0

PHP的隐藏特性有哪些?

vote up0vote downstar

你印象最深的有哪些?

 

1 个答复

vote up0vote down

$$:

$foo = 'bar';
$bar = 'foobar';
echo $$foo;    //This outputs foobar

function bar() {
    echo 'Hello world!';
}

function foobar() {
    echo 'What a wonderful world!';
}
$foo();    //This outputs Hello world!
$$foo();    //This outputs What a wonderful world!

stdClass:

$person = array();
$person['name'] = 'bob';
$person['age'] = 5;
$string = $person['name'] . ' is ' . $person['age'] . ' years old.';

可以用stdClass写成:

$person = new stdClass();
$person->name = 'bob';
$person->age = 5;
$string = "$person->name is $person->age years old.";

or:

$page = (int) @$_GET['page'] 
  or $page = 1;

只有$_GET['page']的布尔值为true$page = 1才会被运行,因为or的优先级比=

and:

<?php $flag and print "Blah" ?>

只有$flagtrue时才会打印,跟or类似。

extract函数:

function render_template($template_name, $context)
{
    extract($context);
    。。。
}

该函数在模板引擎中很有用,如果你调用render_template('index.html', array('foo' => 'bar'))那么在函数内部将有一个$foo变量,它的值为'bar'

先这些了,后面补上!

链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.