麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > PHP > 正文

如何通過php 將print_r處理后的數(shù)據(jù)還原為原始數(shù)組

2020-03-22 19:50:50
字體:
供稿:網(wǎng)友

php print_r方法可以把變量打印顯示,使變量易于理解。如果變量是string,integer或float,將打印變量值本身,如果變量是array,將會按照一定格式顯示鍵和元素。object與數(shù)組類似。print_r用于打印數(shù)組較多。

php原生沒有把print_r方法打印后的數(shù)據(jù)還原為原始數(shù)組,因此寫了下面這個方法,實現(xiàn)將print_r處理后的數(shù)據(jù)還原為原始數(shù)組。

RestorePrint.html' target='_blank'>class.php

 ?php/** * 將print_r處理后的數(shù)據(jù)還原為原始數(shù)組 * Date: 2016-10-31 * Author: fdipzone * Ver: 1.0 */class RestorePrint{ // class start public $res = array(); protected $dict = array(); protected $buf = protected $keyname = protected $stack = array(); public function __construct() { $this- stack[] = $this-  } public function __call($method, $param){ echo $this- buf . not defined mehtod: .$method. param: .implode( , , $param); } public function set($word, $value= ){ if(is_array($word)){ foreach($word as $k= $v){ $this- set($k, $v); } $p = $this- dict; foreach(str_split($word) as $ch){ if(!isset($p[$ch])){ $p[$ch] = array(); } $p = $p[$ch]; } $p[ val ] = $value; return $this; } public function parse($str){ $this- doc = $str; $this- len = strlen($str); $i = 0; while($i $this- len){ $t = $this- find($this- dict, $i); if($t){ $i = $t; $this- buf =  }else{ $this- buf .= $this- doc{$i++}; } protected function find( $p, $i){ if($i = $this- len){ return $i; } $t = 0; $n = $this- doc{$i}; if(isset($p[$n])){ $t = $this- find($p[$n], $i+1); } if($t){ return $t; } if(isset($p[ val ])){ $arr = explode( , , $p[ val  call_user_func_array(array($this, array_shift($arr)), $arr); return $i; } return $t; } protected function group(){ if(!$this- keyname){ return ; } $cnt = count($this- stack)-1; $this- stack[$cnt][$this- keyname] = array(); $this- stack[] = $this- stack[$cnt][$this- keyname]; $this- keyname =  } protected function brackets($c){ $cnt = count($this- stack)-1; switch($c){ case ) : if($this- keyname){ $this- stack[$cnt][$this- keyname] = trim($this- buf); } $this- keyname =  array_pop($this- stack); break; case [ : if($this- keyname){ $this- stack[$cnt][$this- keyname] = trim($this- buf); } break; case ] : $this- keyname = $this- break; } $this- buf = } // class end? 

demo.php

 ?phprequire RestorePrint.class.php $print_r_data = TXTArray [name] = fdipzone [gender] = male [age] = 18 [profession] = programmer [detail] = Array( [grade] = 1 [addtime] = 2016-10-31TXT;// 顯示打印的數(shù)據(jù)echo 顯示打印的數(shù)據(jù) br echo pre .$print_r_data. /pre $oRestorePrint = new RestorePrint;$oRestorePrint- set( Array , group $oRestorePrint- set( [ , brackets,[ $oRestorePrint- set( ] = , brackets,] $oRestorePrint- set( ) , brackets,) $oRestorePrint- parse($print_r_data);$result = $oRestorePrint- echo 還原為數(shù)組 br var_dump($result);? 

輸出:

顯示打印的數(shù)據(jù)Array( [name] = fdipzone [gender] = male [age] = 18 [profession] = programmer [detail] = Array( [grade] = 1 [addtime] = 2016-10-31還原為數(shù)組array (size=5) name = string fdipzone (length=8) gender = string male (length=4) age = string 18 (length=2) profession = string programmer (length=10) detail =  array (size=2) grade = string 1 (length=1) addtime = string 2016-10-31 (length=10)

本文講解了php 將print_r處理后的數(shù)據(jù)還原為原始數(shù)組的方法,更多相關(guān)內(nèi)容請關(guān)注php 。

相關(guān)推薦:

通過php中的PDO判斷連接是否可用的方法

通過php 判斷頁面或圖片是否經(jīng)過gzip壓縮

HTML5獲取當(dāng)前地理位置并在百度地圖上展示的實例

以上就是如何通過php 將print_r處理后的數(shù)據(jù)還原為原始數(shù)組的方法的詳細(xì)內(nèi)容,PHP教程

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 亚洲福利视 | 成人福利在线免费观看 | 又黄又爽免费无遮挡在线观看 | 爱看久久| 黄色毛片视频在线观看 | 欧美性受xxxx人人本视频 | 黄色网址在线免费播放 | 一本色道精品久久一区二区三区 | 性欧美xxxx免费岛国不卡电影 | 欧美成人精品欧美一级 | 91久久国产综合久久91猫猫 | 国产精品视频一区二区三区四区五区 | 一级成人黄色片 | 欧美一级爱操视频 | 日本成人午夜 | 日本欧美视频 | 爱福利视频 | av色先锋| 久久精品国产亚洲7777小说 | 欧美成人精品一区二区三区 | 91看片在线观看视频 | 久久国产亚洲精品 | 日本欧美一区二区三区在线观看 | 欧美日韩免费一区 | av成人在线观看 | 欧美精品成人一区二区三区四区 | 久久久久久久99 | 色中色综合 | 99精品在线观看 | 免费国产自久久久久三四区久久 | 天天看天天摸天天操 | 日本中文不卡视频 | 国产毛片网 | 天天艹综合 | 天天碰天天操 | 日韩视频在线免费 | 久久久久久久久久久久久国产精品 | 羞羞视频一区二区 | 成年人黄色片视频 | 欧美色大成网站www永久男同 | 精品国产一区二区三区久久久 |