亚洲国产日韩欧美在线a乱码,国产精品路线1路线2路线,亚洲视频一区,精品国产自,www狠狠,国产情侣激情在线视频免费看,亚洲成年网站在线观看

PHP中串行化用法

時(shí)間:2025-09-24 13:56:56 php語言 我要投稿

PHP中串行化用法

  串行化大概就是把一些變量轉(zhuǎn)化成為字符串的字節(jié)流的形式,這樣比較容易傳輸、存儲(chǔ)。當(dāng)然,關(guān)是傳輸存儲(chǔ)沒有什么,關(guān)鍵是變成串的形式以后還能夠轉(zhuǎn)化回來,而且能夠保持原來數(shù)據(jù)的結(jié)構(gòu)。以下是小編為大家搜索整理的PHP中串行化用法,希望能給大家?guī)韼椭?更多精彩內(nèi)容請及時(shí)關(guān)注我們應(yīng)屆畢業(yè)生考試網(wǎng)!

  1. Person.class.php:

  */

  class Person{ /pic/p>

  public $age;

  private $name;

  protected $sex;

  public function __construct($age="",$name="",$sex=""){

  $this -> age = $age;

  $this -> name = $name;

  $this -> sex = $sex;

  }

  public function say(){

  return $this -> age." ".$this -> name." ".$this -> sex;

  }

  function __sleep(){ /pic/p>

  $arr = array("age","name");

  return $arr;

  }

  function __wakeup(){ /pic/p>

  $this -> sex = "woman";

  }

  }

  2. 串行化代碼

  require("./Person.class.php");

  $p = new Person(21,"du","man"); /pic/p>

  $pString = serialize($p); /pic/p>

  file_put_contents("./file.txt",$pString);/pic/p>

  3. 反串行化代碼

  require("./Person.class.php");/pic/p>

  $pString = file_get_contents("./file.txt");/pic/p>

  $p = unserialize($pString);/pic/p>

【PHP中串行化用法】相關(guān)文章:

php中fsockopen用法實(shí)例08-14

php中引用的用法分析03-04

php中rename函數(shù)用法11-27

php中return的用法實(shí)例分析09-04

PHP中l(wèi)ist方法用法示例10-20

PHP中redis的用法深入分析10-17

php中in-array函數(shù)用法分析01-18

PHP中final關(guān)鍵字用法08-21

PHP中for循環(huán)語句的幾種“變態(tài)”用法09-29

  • 相關(guān)推薦