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