• <i id='5gfEa'><tr id='5gfEa'><dt id='5gfEa'><q id='5gfEa'><span id='5gfEa'><b id='5gfEa'><form id='5gfEa'><ins id='5gfEa'></ins><ul id='5gfEa'></ul><sub id='5gfEa'></sub></form><legend id='5gfEa'></legend><bdo id='5gfEa'><pre id='5gfEa'><center id='5gfEa'></center></pre></bdo></b><th id='5gfEa'></th></span></q></dt></tr></i><div id='5gfEa'><tfoot id='5gfEa'></tfoot><dl id='5gfEa'><fieldset id='5gfEa'></fieldset></dl></div>
    <legend id='5gfEa'><style id='5gfEa'><dir id='5gfEa'><q id='5gfEa'></q></dir></style></legend>

        <tfoot id='5gfEa'></tfoot>

          <bdo id='5gfEa'></bdo><ul id='5gfEa'></ul>

        <small id='5gfEa'></small><noframes id='5gfEa'>

        php中serialize与unserialize用法实例代码

        serialize():将对象转化为字符串保存、unserialize():将字符串反转为对象(对应的类也必须包含) serialize -- 产生一个可存储的值的表示;返回字符串,此字符串包含了表示 value 的字节流,可以存储于任何地方 /* 串行化(序列化) */class Person { public $nam

        <i id='vsaWB'><tr id='vsaWB'><dt id='vsaWB'><q id='vsaWB'><span id='vsaWB'><b id='vsaWB'><form id='vsaWB'><ins id='vsaWB'></ins><ul id='vsaWB'></ul><sub id='vsaWB'></sub></form><legend id='vsaWB'></legend><bdo id='vsaWB'><pre id='vsaWB'><center id='vsaWB'></center></pre></bdo></b><th id='vsaWB'></th></span></q></dt></tr></i><div id='vsaWB'><tfoot id='vsaWB'></tfoot><dl id='vsaWB'><fieldset id='vsaWB'></fieldset></dl></div>
          <tbody id='vsaWB'></tbody>

        <small id='vsaWB'></small><noframes id='vsaWB'>

            <bdo id='vsaWB'></bdo><ul id='vsaWB'></ul>

              <tfoot id='vsaWB'></tfoot>
            1. <legend id='vsaWB'><style id='vsaWB'><dir id='vsaWB'><q id='vsaWB'></q></dir></style></legend>
                • serialize():将对象转化为字符串保存、unserialize():将字符串反转为对象(对应的类也必须包含)
                  serialize --  产生一个可存储的值的表示;返回字符串,此字符串包含了表示value的字节流,可以存储于任何地方
                  /*  
                   串行化(序列化)  
                  */
                  class Person  
                  {  
                   public $name;  
                   public $age;  
                   public $sex;  
                   public $sanwei;
                  
                   public function __construct($name, $age, $sex, $sanwei)  
                   {  
                    $this->name = $name;  
                    $this->age = $age;  
                    $this->sex = $sex;  
                    $this->sanwei = $sanwei;  
                   }  
                  }
                  
                  // 实例化Person类  
                  $p = new Person('凤姐', 20, '女', '100-70-100');  
                  var_dump($p);  
                  $str = serialize($p); // O:6:"Person":3:{s:4:"name";s:6:"凤姐";s:3:"age";i:20;s:3:"sex";s:3:"女";}
                  
                  file_put_contents('9.txt', $str);  
                  /*  
                   O:object  
                   6:类名的字符个数  
                   Person:类名  
                   3:三个属性  
                   s:string 数据类型   
                   i:int 数据类型  
                  */
                  unserialize($param) :反串行化
                  class Person  
                  {  
                      public $name;  
                      public $age;  
                      public $sex;  
                      public $sanwei;
                  
                      public function __construct($name, $age, $sex, $sanwei)  
                      {  
                          $this->name = $name;  
                          $this->age = $age;  
                          $this->sex = $sex;  
                          $this->sanwei = $sanwei;  
                      }  
                  }
                  
                  // 1.获取9.txt文本的内容  
                  $str = file\_get\_contents('9.txt');//O:6:"Person":4:{s:4:"name";s:6:"凤姐";s:3:"age";i:20;s:3:"sex";s:3:"女";s:6:"sanwei";s:10:"100-70-100";}
                  
                  // 2.反串行化  
                  $obj = unserialize($str);
                  
                  echo $obj->name;  
                  echo $obj->age;  
                  echo $obj->sex;
                  例子:
                  $intParam = 123;
                  $stringParam= 'I love the world';  
                  $arrayParam = array(  
                      "fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"),  
                      "numbers" => array(1, 2, 3, 4, 5, 6),  
                      "holes" => array("first", 5 => "second", "third")  
                  ); 
                  
                  class Object  
                  {  
                      public $memu = "index";  
                  }  
                  $objectParam = new Object();  
                  
                  print 'serialize($intParam) 输出的值:'.serialize($intParam);
                  print 'serialize($stringParam) 输出的值:'.serialize($stringParam);
                  print 'serialize($arrayParam) 输出的值:'.serialize($c=$arrayParam);  
                  print 'serialize($objectParam) 输出的值:'.serialize($d=$objectParam);
                  print 'unserialize(serialize($intParam)) 的结果是:'.unserialize(serialize($intParam));
                  print 'unserialize(serialize($stringParam)) 的结果是:'.unserialize(serialize($stringParam));
                  
                  print 'unserialize(serialize($arrayParam)) 的结果是:'.unserialize(serialize($arrayParam));
                  var_dump(unserialize(serialize($arrayParam)));  
                  
                  print 'unserialize(serialize($objectParam)) 的结果是:';
                  var_dump(unserialize(serialize($objectParam)));
                  结果代码:
                  serialize($intParam) 输出的值:i:123;
                  serialize($stringParam) 输出的值:s:16:"I love the world";
                  serialize($arrayParam) 输出的值:a:3:{s:6:"fruits";a:3:{s:1:"a";s:6:"orange";s:1:"b";s:6:"banana";s:1:"c";s:5:"apple";}s:7:"numbers";a:6:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;i:5;i:6;}s:5:"holes";a:3:{i:0;s:5:"first";i:5;s:6:"second";i:6;s:5:"third";}}
                  serialize($objectParam) 输出的值:O:6:"Object":1:{s:4:"memu";s:5:"index";}
                  unserialize(serialize($intParam)) 的结果是:123
                  unserialize(serialize($stringParam)) 的结果是:I love the world
                  
                  unserialize(serialize($arrayParam)) 的结果是:Arrayarray(3) {
                    ["fruits"]=>
                    array(3) {
                      ["a"]=>
                      string(6) "orange"
                      ["b"]=>
                      string(6) "banana"
                      ["c"]=>
                      string(5) "apple"
                    }
                    ["numbers"]=>
                    array(6) {
                      [0]=>
                      int(1)
                      [1]=>
                      int(2)
                      [2]=>
                      int(3)
                      [3]=>
                      int(4)
                      [4]=>
                      int(5)
                      [5]=>
                      int(6)
                    }
                    ["holes"]=>
                    array(3) {
                      [0]=>
                      string(5) "first"
                      [5]=>
                      string(6) "second"
                      [6]=>
                      string(5) "third"
                    }
                  }
                  
                  unserialize(serialize($objectParam)) 的结果是:object(Object)#2 (1) {
                    ["memu"]=>
                    string(5) "index"
                  }
                  
                   
                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  php获取数组中某一个元素的值,并用逗号分隔 //打印方法function pp($ay){echo "pre";print_r($ay);}//定义数组$user_list=array('0'=['id'=1,'name'='刘德华'],'1'=['id'=2,'name'='张学友'],'2'=['id'=3,'name'='黎明'],'3'=['id'=4,'name'='郭富城']);pp(
                  本文主要和大家分享一篇php 读写json文件及修改json的方法,具有很好的参考价值,希望能帮助到大家。实例代码如下: //追加写入用户名下文件$code="001";//动态数据$json_string=file_get_contents("text.json");//从文件中读取数据到PHP变量$data=json_decod
                  PHP对Excel导入导出操作 最近公司要做报表功能,各种财务报表、工资报表、考勤报表等,于是特地封装适用各大场景的导入导出操作,希望大神支出不足之处。 phpspreadsheet 引入 由于PHPExcel早就停止更新维护,所以适用phpspreadsheet。不知道如何通过composer
                  使用PhpOffice\PhpSpreadsheet 实现Excel多sheet导出代码,具体代码如下: /** * 多sheet的导出 * @author bwy xxx@xxx.com * @param [type] $data_array * @return void */ public function xtexport($data_array) { $name = '团长' . date("Y-m-d", time())
                  首先安装PhpSpreadsheet composer require phpoffice/phpspreadsheet 导入导出代码入下: use PhpOffice\PhpSpreadsheet\Spreadsheet;use PhpOffice\PhpSpreadsheet\Writer\Xlsx;use PhpOffice\PhpSpreadsheet\Reader\Xlsx as ReaderXlsx;use PhpOffice\PhpSp
                  PHP实现图片加水印代码,具体代码如下: //$img = 图片,$source = 水印 $img = 'test.jpg'; $source = 'source.png'; //参数设置,值越大水印越稀(水印平铺的越少),相反... $ww = 0; //每个水印的左右间距 $hh = 0; //每个水印的上下间距 //水印图片旋转

                    <legend id='g2MsI'><style id='g2MsI'><dir id='g2MsI'><q id='g2MsI'></q></dir></style></legend>
                      <tbody id='g2MsI'></tbody>
                    <tfoot id='g2MsI'></tfoot>

                        <bdo id='g2MsI'></bdo><ul id='g2MsI'></ul>

                          • <i id='g2MsI'><tr id='g2MsI'><dt id='g2MsI'><q id='g2MsI'><span id='g2MsI'><b id='g2MsI'><form id='g2MsI'><ins id='g2MsI'></ins><ul id='g2MsI'></ul><sub id='g2MsI'></sub></form><legend id='g2MsI'></legend><bdo id='g2MsI'><pre id='g2MsI'><center id='g2MsI'></center></pre></bdo></b><th id='g2MsI'></th></span></q></dt></tr></i><div id='g2MsI'><tfoot id='g2MsI'></tfoot><dl id='g2MsI'><fieldset id='g2MsI'></fieldset></dl></div>
                          • <small id='g2MsI'></small><noframes id='g2MsI'>