当前位置:首页 > PHP问题 > 正文内容

php单箭头和双箭头区分【php问题】,php,箭头

搜教程4年前 (2019-11-27)PHP问题151

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网别的相干文章!

扫描二维码推送至手机访问。

版权声明:本文由搜教程网发布,如需转载请注明出处。

本文链接:https://www.sojiaocheng.cn/13514.html

标签: php箭头
分享给朋友:

“php单箭头和双箭头区分【php问题】,php,箭头” 的相关文章

​APP开辟必备模拟器:夜神模拟器下载和使用方法(图文)【php问题】,模拟器

​APP开辟必备模拟器:夜神模拟器下载和使用方法(图文)【php问题】,模拟器

这篇文章重要引见了关于APP开辟必备模仿器:夜神模仿器下载和使用方法(图文),有着肯定的参考价值,如今分享给人人,有须要的朋侪能够参考一下 APP开辟必备模仿器:夜神模仿器下载和使用方法(图文) App开辟完成后,须要测试,本钱有限,不能买一切的机型举行测试。跟人人分享一个,安卓模仿器,模仿...

php array_sum函数怎样用【php问题】,php array_sum

php array_sum函数怎样用【php问题】,php array_sum

php array_sum函数用于盘算返回数组中一切值的和,其语法是array_sum(arra),参数array必须,指划定数组。 php array_sum函数怎样用? 作用:返回数组中一切值的和。 语法: array_sum(arra) 参数: array 必须。划定数组。...

php is_executable函数怎样用【php问题】,php is_executable

php is_executable函数怎样用【php问题】,php is_executable

php is_executable函数用于搜检指定的文件是不是可实行,其语法是is_executable(file),参数file是必须的,指规定要搜检的文件。 php is_executable函数怎样用? 作用:搜检指定的文件是不是可实行。 语法: is_executable(f...

php mysqli_num_fields函数怎样用【php问题】,php,mysqli_num_fields

php mysqli_num_fields函数怎样用【php问题】,php,mysqli_num_fields

php mysqli_num_fields函数用于返回效果集合字段(列)的数目,其语法是mysqli_num_fields(result),参数result必须,指划定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的效果...

php html_entity_decode函数怎样用【php问题】,php,html_entity_decode函数

php html_entity_decode函数怎样用【php问题】,php,html_entity_decode函数

html_entity_decode()函数用于把 HTML 实体转换为字符,语法为html_entity_decode(string,flags,character-set)。 php html_entity_decode()函数怎样用? html_entity_decode() 函数...

php count函数怎样用【php问题】,php count

php count函数怎样用【php问题】,php count

php count函数用于返回数组中元素的数量,其语法是count(array,mode),参数array必须,指划定要计数的数组。 php count函数怎样用? 定义和用法 count() 函数返回数组中元素的数量。 语法 count(array,mode); 参数 ar...