<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bonnes pratiques : Astuces de programmation Le MEMO du Web Développeur</title>
	<atom:link href="https://memo-web.fr/tag/bonnes-pratiques/feed/" rel="self" type="application/rss+xml" />
	<link>https://memo-web.fr</link>
	<description></description>
	<lastBuildDate>Fri, 10 Apr 2020 07:04:26 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>Bonne pratique : Syntaxes du if then else en PHP</title>
		<link>https://memo-web.fr/categorie-php-179/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=categorie-php-179</link>
					<comments>https://memo-web.fr/categorie-php-179/#respond</comments>
		
		<dc:creator><![CDATA[t@ra]]></dc:creator>
		<pubDate>Thu, 31 Jan 2013 14:34:39 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Bonnes pratiques]]></category>
		<guid isPermaLink="false">http://memo-web.fr/?p=113</guid>

					<description><![CDATA[<p>Les expressions conditionnelles en PHP, différents cas de figure. Version simplifiée d&#8217;une expression conditionnelle en PHP if (condition1)? (instruction2) : (instruction3); Si condition1 est vérifiée alors on exécute instruction2 sinon on exécute instruction3 Exemple&#160;: le code suivant : if ($couleur == "ouvert") echo 'c'est ouvert'; else echo 'c'est fermé'; Peut être remplacé de façon plus [&#8230;]</p>
The post <a href="https://memo-web.fr/categorie-php-179/">Bonne pratique : Syntaxes du if then else en PHP</a> first appeared on <a href="https://memo-web.fr">Le MEMO du Web Développeur</a>.]]></description>
										<content:encoded><![CDATA[<p>Les expressions conditionnelles en PHP, différents cas de figure.</p>



<h2 class="wp-block-heading">Version simplifiée d&rsquo;une expression conditionnelle en PHP</h2>



<pre class="wp-block-preformatted">if (condition1)? (instruction2) : (instruction3);</pre>



<p>Si condition1 est vérifiée alors on exécute instruction2 sinon on exécute instruction3</p>



<p>Exemple&nbsp;:</p>



<p>le code suivant :</p>



<pre class="wp-block-preformatted">if ($couleur == "ouvert")
  echo 'c'est ouvert';
else
  echo  'c'est fermé';</pre>



<p>Peut être remplacé de façon plus élégante par le code ci-dessous :</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">(couleur==ouvert)?$str='c\'est ouvert' : $str'c\'est fermé';
echo $str;</pre>



<h2 class="wp-block-heading">Version multi conditionnelle</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">if (condition1) : instruction1 elseif (condition2) : instruction2 else() instruction3 endif;

&lt;?php if ($meteo == "Soleil") : ?>
  Super. &lt;br>
  Je vais prendre un café en terrasse !
&lt;?php elseif ($meteo == "Pluie") : ?>
  Super. &lt;br/>
  Je vais patauger dans les flaques ! 
&lt;?php else : ?>
  Bon. &lt;br/>
  Je continue à bosser.
&lt;?php endif;?></pre>
<div style="margin-top: 0px; margin-bottom: 0px;" class="sharethis-inline-share-buttons" ></div>The post <a href="https://memo-web.fr/categorie-php-179/">Bonne pratique : Syntaxes du if then else en PHP</a> first appeared on <a href="https://memo-web.fr">Le MEMO du Web Développeur</a>.]]></content:encoded>
					
					<wfw:commentRss>https://memo-web.fr/categorie-php-179/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
