KennisbankExamencentrum
NL · NLNederlands (Nederland)
Taal kiezen13

CKTIS / PHP

Expressies en operatoren

Voorrang groepeert operatoren.

Versie: PHP 8.4; repository runtime, production runtime not attested

Syntax

($a + $b) * $c; $left && $right;

Voorrang groepeert operatoren. Vermenigvuldiging bindt sterker dan optelling en haakjes wijzigen de groepering. && slaat rechts over als links onwaar is. Groepering op zich garandeert geen evaluatievolgorde voor onafhankelijke operanden.

$calls=0; $check=function() use (&$calls){++$calls;return true;}; $a=false && $check(); $b=true && $check();
echo json_encode([2+3*4,(2+3)*4,$a,$b,$calls]);
[14,20,false,true,1]

Voorbeelden

<?php
$calls=0; $check=function() use (&$calls){++$calls;return true;}; $a=false && $check(); $b=true && $check();
echo json_encode([2+3*4,(2+3)*4,$a,$b,$calls]);

Resultaat

[14,20,false,true,1]

Bronnen