PHP Print_r How to restore an array of code principles?

Source: Internet
Author: User
Class Trie {protected $dict = array ();    protected $buf = ";      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;      The 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 '])) {$ar = explode (', ', $p [' Val ']); CalL_user_func_array (Array ($this, Array_shift ($ar)), $ar);      return $i;    } return $t; } function __call ($method, $param) {echo ' ****\n$this->buf undefined method: $method parameter: ". Join (', ', $param). "
\ n "; }} class App extends Trie {public $res = array (); Protected $stack = Array (); protected $keyname = "; protected $buf = "; function __construct () {$this->stack[] =& $this->res; } 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-& GT;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->buf; } $this->buf = "; } }

This code I see in a few examples, the original source does not know, it is how to achieve print_r display of the array? Ask for comments, thank you!
& is often used in the middle, and I get dizzy when I go back and forth.

Reply content:

Class Trie {protected $dict = array ();    protected $buf = ";      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;      The 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 '])) {$ar = explode (', ', $p [' Val ']); Aa.L_user_func_array (Array ($this, Array_shift ($ar)), $ar);      return $i;    } return $t; } function __call ($method, $param) {echo ' ****\n$this->buf undefined method: $method parameter: ". Join (', ', $param). "
\ n "; }} class App extends Trie {public $res = array (); Protected $stack = Array (); protected $keyname = "; protected $buf = "; function __construct () {$this->stack[] =& $this->res; } 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-& GT;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->buf; } $this->buf = "; } }

This code I see in a few examples, the original source does not know, it is how to achieve print_r display of the array? Ask for comments, thank you!
& is often used in the middle, and I get dizzy when I go back and forth.

&Represents a reference, such as

$a = &$b;

On behalf of $a and being the same reference, the modification also modifies $b $a $b the value, and the modification $b also affects $a . Do not add & $b a copy of the value on behalf of the given $a , both are independent.

and the function (method) of the parameter list plus & , it means to pass by reference, not add is by value, this is the basic concept of programming, do not say it.

It is important to note that the object type, whether added or not, & is a reference.

Check this out

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.