call_user_func_array
trait
array_walk
PHP
的ArrayAccess
接口介绍ArrayAccess
的作用是使你的Class
看起来像一个数组(PHP
的数组)。
下面是 ArrayAccess 的定义:
interface ArrayAccess{
boolean offsetExists($index)
mixed offsetGet($index)
void offsetSet($index, $newvalue)
void offsetUnset($index)
}
class Configuration implements ArrayAccess {
static private $config;
private $configarray;
private function __construct() {
// init
$this->configarray = array("Binzy" => "Male", "Jasmin" => "Female");
}
public static function instance() {
if (self::$config == null) {
self::$config = new Configuration();
}
return self::$config;
}
//检查一个偏移位置是否存在
function offsetExists($index) {
return isset($this->configarray[$index]);
}
//获取一个偏移位置的值
function offsetGet($index) {
return $this->configarray[$index];
}
//设置一个偏移位置的值
function offsetSet($index, $newvalue) {
$this->configarray[$index] = $newvalue;
}
//复位一个偏移位置的值
function offsetUnset($index) {
unset($this->configarray[$index]);
}
}
$config = Configuration::instance();
print_r($config);
echo "<br/>";
echo $config['Binzy'];
echo "<br/>";
- array_reverse 函数返回翻转顺序的数组
- http_build_query
- parse_str:将一个url ?后面的参数转换成一个数组,array parse_str(url,arr)。