onethink-(03)-php内置函数

php内置函数有1300多个?但是平时接触到的也就那么10几个


array_pop() 函数删除数组中的最后一个元素,并返回最后的那个元素。

例子

<?php
$a=array("Dog","Cat","Horse");
array_pop($a);
print_r($a);
?>

输出:

Array ( [0] => Dog [1] => Cat )




parse_str() 函数把查询字符串解析到变量中。

例子 1

<?php
parse_str("id=23&name=John%20Adams");
echo $id."<br />";
echo $name;
?>

输出:

23
John Adams

例子 2

<?php
parse_str("id=23&name=John%20Adams",$myArray);
print_r($myArray);
?>

输出:

Array
(
[id] => 23
[name] => John Adams
)

call_user_func_array

call_user_func_array

(PHP 4 >= 4.0.4, PHP 5)

call_user_func_array — Call a callback with an array of parameters
说明
mixed call_user_func_array ( callable $callback , array $param_arr )

Calls the callback given by the first parameter with the parameters in param_arr.
参数

callback

    The callable to be called.
param_arr

    The parameters to be passed to the callback, as an indexed array.

返回值

Returns the return value of the callback, or FALSE on error.

php函数serialize()与unserialize()


 php函数serialize()与unserialize()

serialize()和unserialize()在php手册上的解释是:

serialize — Generates a storable representation of a value

serialize — 产生一个可存储的值的表示

unserialize — Creates a PHP value from a stored representation

unserialize — 从已存储的表示中创建 PHP 的值

<?php
//声明一个类
class dog {

    var $name;
    var $age;
    var $owner;

    function dog($in_name="unnamed",$in_age="0",$in_owner="unknown") {
        $this->name = $in_name;
        $this->age = $in_age;
        $this->owner = $in_owner;
    }

    function getage() {
        return ($this->age * 365);
    }
   
    function getowner() {
        return ($this->owner);
    }
   
    function getname() {
        return ($this->name);
    }
}
//实例化这个类
$ourfirstdog = new dog("Rover",12,"Lisa and Graham");
//用serialize函数将这个实例转化为一个序列化的字符串
$dogdisc = serialize($ourfirstdog);
print $dogdisc; //$ourfirstdog 已经序列化为字符串 O:3:"dog":3:{s:4:"name";s:5:"Rover";s:3:"age";i:12;s:5:"owner";s:15:"Lisa and Graham";}

print '<BR>';

/*
-----------------------------------------------------------------------------------------
    在这里你可以将字符串 $dogdisc 存储到任何地方如 session,cookie,数据库,php文件
-----------------------------------------------------------------------------------------
*/

//我们在此注销这个类
unset($ourfirstdog);

/*    还原操作   */

/*
-----------------------------------------------------------------------------------------
    在这里将字符串 $dogdisc 从你存储的地方读出来如 session,cookie,数据库,php文件
-----------------------------------------------------------------------------------------
*/


//我们在这里用 unserialize() 还原已经序列化的对象
$pet = unserialize($dogdisc); //此时的 $pet 已经是前面的 $ourfirstdog 对象了
//获得年龄和名字属性
$old = $pet->getage();
$name = $pet->getname();
//这个类此时无需实例化可以继续使用,而且属性和值都是保持在序列化之前的状态
print "Our first dog is called $name and is $old days old<br>";
print '<BR>';
?>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值