gpt4 book ai didi

php - 为什么我需要 "&"?

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:06:23 24 4
gpt4 key购买 nike

请参阅网络上有关 PHP 工厂模式的示例。

$kind =& Vehicle::category($wheel); 行中,我为什么要使用 &

代码:

<?php
class Vehicle {

function category($wheel = 0) {
if ($wheel == 2) {
return "Motor";
} elseif($wheel == 4) {
return "Car";
}
}
}

class Spec {

var $wheel = '';

function Spec($wheel) {
$this->wheel = $wheel;
}

function name() {
$wheel = $this->wheel;
return Vehicle::category($wheel);
}

function brand() {
$wheel = $this->wheel;
$kind =& Vehicle::category($wheel);
if ($kind == "Motor") {
return array('Harley','Honda');
} elseif($kind = "Car") {
return array('Nisan','Opel');
}
}
}

$kind = new Spec(2);
echo "Kind: ".$kind->name();
echo "<br>";
echo "Brand: " . implode(",", $kind->brand());
?>

最佳答案

来自 Stack Overflow 问题 Reference - What does this symbol mean in PHP? :

=& 引用

正如(已删除的)评论所说,最后一个链接应该适用于您的具体情况。

关于php - 为什么我需要 "&"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10569984/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com