
php单箭头和双箭头区分:
援用一个类的属性和要领就运用->标记。
下面是一个例子小顺序:
<?php //定义类Cart class Cart { var $items; // 购物车中的物品 // 将 $num 个 $artnr 物品到场购物车 function add_item($artnr, $num) { $this->items[$artnr] += $num; } // 将 $num 个 $artnr 物品从购物车中掏出 function remove_item($artnr, $num) { if ($this->items[$artnr] > $num) { $this->items[$artnr] -= $num; return true; } elseif ($this->items[$artnr] == $num) { unset($this->items[$artnr]); return true; } else { return false; } } } //示例继续定义类Named_Cart class Named_Cart extends Cart { var $owner; function set_owner ($name) { $this->owner = $name; } } //运用类的代码 $ncart = new Named_Cart; // 新建一个有名字的购物车 $ncart->set_owner("kris"); // 给该购物车定名 print $ncart->owner; // 输出该购物车主人的名字 $ncart->add_item("10", 1); // (从购物车类中继续来的功用) ?>
“->”这个箭头也可所以挪用类中的函数
class a { function b() { echo 'a'; } } $a=new a; $a->b(); 输出:a
=>如许的箭头,定义数组用:
$array1 = array('a' = >5, 'b' = >6); while ($arrayitem = each($array1)) { extract($arrayitem); echo('<br />'.$key.'='.$value); } 输出:a = 5 b = 6
总结:php单箭头“->”用来援用一个类的属性和要领或挪用类中的函数。双箭头“=>”用来定义数组。
引荐:php服务器
以上就是php单箭头和双箭头区分的细致内容,更多请关注ki4网别的相干文章!