gpt4 book ai didi

php 语法 $a = $b = 1;

转载 作者:行者123 更新时间:2023-12-03 23:55:36 25 4
gpt4 key购买 nike

$a = 1;
$b = $a;

等于写这个?

$a = $b = 1;

第二个示例是否总是将 1 作为 $a 和 $b 的值,即使 $a 和 $b 已经分配了一个值?

最佳答案

Quoting the documentation:

The value of an assignment expression is the value assigned. That is, the value of "$a = 3" is 3. This allows you to do some tricky things:

<?php

$a = ($b = 4) + 5; // $a is equal to 9 now, and $b has been set to 4.

?>

所以,为了回答您的问题,赋值 $b = 1 的结果是 1,因此,$a = $b = 1 将赋值$b = 1——也就是1——到$a.

话虽如此,滥用它会导致代码难以阅读。

关于php 语法 $a = $b = 1;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15140007/

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