note 126985 added to control-structures.if

From: Date: Tue, 12 Apr 2022 22:32:03 +0000
Subject: note 126985 added to control-structures.if
Groups: php.notes 
Request: Send a blank email to php-notes+get-218243@lists.php.net to get a copy of this message
You have two ways to use conditions in php. 1: <?php if ($condition1) { // code if $condition1 is true } elseif ($condition2) { // code if $condition2 is true // note that I don't use space between "else" and "if"! // you are possible to use space ("else if") ONLY in this syntax // it works because you are using TWO if's. // if (...) { // ... // } else { // if (...) { // ... // } // } } else { // code if all of conditions are false } ?> Second syntax is better for combining PHP and HTML. Because you can also use this syntax for "FOR", "FOREACH", and "SWITCH" statements. And it lets you read your code easily. 2: <?php if ($condition1): // code if $condition1 is true ?> some html codes... <?php elseif ($condition2): // code if $condition2 is true ?> some html codes... <?php // note that you CANNOT use "else if" in this syntax! // it means you MUST use "elseif". else: // code if both $condition1 and $condition2 are false endif; // as you see, if you have a lot of statements, you can read them easily ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 94.130.124.121) ---- Manual Page -- https://php.net/manual/en/control-structures.if.php Edit -- https://main.php.net/note/edit/126985 Del: integrated -- https://main.php.net/note/delete/126985/integrated Del: useless -- https://main.php.net/note/delete/126985/useless Del: bad code -- https://main.php.net/note/delete/126985/bad+code Del: spam -- https://main.php.net/note/delete/126985/spam Del: non-english -- https://main.php.net/note/delete/126985/non-english Del: in docs -- https://main.php.net/note/delete/126985/in+docs Del: other reasons-- https://main.php.net/note/delete/126985 Reject -- https://main.php.net/note/reject/126985 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#218243) next »