"www.111cn.net",""/> "www.111cn.net","">
Home > php教程 > PHP源码 > body text

php ->和=>区别与实例教程

WBOY
Release: 2016-06-08 17:27:37
Original
1201 people have browsed it
<script>ec(2);</script>

简单说一下就是
-> 调用对象的成员
=> 指定下标

下面来看几个实例关于-> 与=>代码,让你更清楚是什么用法与功能并且有什么区别了。
*/
// =>用法,可用到数组array,赋值与foreach赋值

$array = array("addr" => "www.111cn.net","tel" => "11111111");

print_r($array);

/*
结果为
Array
(
    [addr] => www.111cn.net
    [tel] => 11111111
)
*/

//用来foreach实例

foreach( $array as $v =>$_v )
{
 echo $_v,'
';
}

/*
结果
www.111cn.net
11111111

*/

// ->用法上面说了是用于对象的,那我们就来做个实验

class user{
 var $url ='www.111cn.net';
 
 public function showUrl()
 {
  echo $this->url;
 }
}

//调用 user类方法

$u = new user();
$u->showUrl();

/*
输出结果为 www.111cn.net

本文章原创于www.111cn.net[中国WEB第一站]转载注明来源

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!