<?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>Tutorial Melayu &#187; kiraan dalam php</title>
	<atom:link href="http://www.tutorialmelayu.com/tag/kiraan-dalam-php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.tutorialmelayu.com</link>
	<description></description>
	<lastBuildDate>Sun, 06 Nov 2011 12:38:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>membuat kiraan dalam php menggunakan operators aritmetik &amp; logik</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/membuat-kiraan-dalam-php-menggunakan-operators-aritmetik-logik</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/membuat-kiraan-dalam-php-menggunakan-operators-aritmetik-logik#comments</comments>
		<pubDate>Sat, 28 Mar 2009 20:21:35 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[kiraan dalam php]]></category>
		<category><![CDATA[logik php]]></category>
		<category><![CDATA[matematik php]]></category>
		<category><![CDATA[php asas]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=79</guid>
		<description><![CDATA[Untuk melakukan pengiraan aritmetik, seperti 2 + 2 atau 17 * 5, kita boleh menggunakan operator berikut; &#60;?php // dua operand a dan b $a = 8; $b = 4; &#160; //tambah $c = $a + $b; echo &#34;hasil tambah $c &#60;br&#62;&#34;; &#160; //tolak $d = $a - $b; echo &#34;hasil tolak $d &#60;br&#62;&#34;; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Untuk melakukan pengiraan aritmetik, seperti 2 + 2 atau 17 * 5, kita boleh menggunakan operator berikut;</p>
<p><span id="more-79"></span></p>

<div class="wp_codebox"><table><tr id="p794"><td class="code" id="p79code4"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// dua operand a dan b</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">8</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$b</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">4</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//tambah</span>
<span style="color: #dfc484;">$c</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">+</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;hasil tambah <span style="color: #dfc484; font-weight: bold;">$c</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//tolak</span>
<span style="color: #dfc484;">$d</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">-</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;hasil tolak <span style="color: #dfc484; font-weight: bold;">$d</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//darab</span>
<span style="color: #dfc484;">$e</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">*</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;hasil darab <span style="color: #dfc484; font-weight: bold;">$e</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//bahagi</span>
<span style="color: #dfc484;">$f</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">/</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;hasil bahagi <span style="color: #dfc484; font-weight: bold;">$f</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//mencari baki hasil dari bahagi</span>
<span style="color: #dfc484;">$g</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">%</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;hasil baki <span style="color: #dfc484; font-weight: bold;">$g</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Terdapat beberapa short form atau singkatan untuk beberapa operasi matematik yang sering digunakan di dalam PHP seperti ++ dan &#8211;.</p>

<div class="wp_codebox"><table><tr id="p795"><td class="code" id="p79code5"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">3</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// cara biasa</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">+</span> <span style="color: #ff8400;">1</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//boleh digantikan dengan </span>
<span style="color: #dfc484;">$a</span><span style="color: #eeeeee;">++;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// cara biasa</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">-</span> <span style="color: #ff8400;">1</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//boleh digantikan dengan </span>
<span style="color: #dfc484;">$a</span><span style="color: #eeeeee;">--;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// cara biasa</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">*</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//boleh digantikan dengan </span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">*=</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// cara biasa</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">/</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//boleh digantikan dengan </span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">/=</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// cara biasa</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">+</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//boleh digantikan dengan </span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">+=</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Manakala operator logik pula digunakan untuk membuat test terhadap sesuatu nilai variable. Ianya selalunya digunakan dengan if else.</p>

<div class="wp_codebox"><table><tr id="p796"><td class="code" id="p79code6"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$b</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">6</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// maksud : kalau $a sama nilai dengan $b</span>
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">==</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>  
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;true &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #e8ed97;">else</span> 
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;false &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// maksud : kalau $a tak sama nilai dengan $b</span>
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">!=</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>  
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;true &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #e8ed97;">else</span> 
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;false &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// maksud : kalau $a lagi besar dari $b</span>
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">&gt;</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>  
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;true &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #e8ed97;">else</span> 
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;false &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// maksud : kalau $a lagi kecil dari $b</span>
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">&lt;</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>  
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;true &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #e8ed97;">else</span> 
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;false &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// maksud : kalau $a sama dengan 10 DAN $b sama dengan 6</span>
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">10</span> <span style="color: #eeeeee;">&amp;&amp;</span> <span style="color: #dfc484;">$b</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">6</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>  
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;true &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #e8ed97;">else</span> 
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;false &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// maksud : kalau $a sama dengan 10 ATAU $b sama dengan 3</span>
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">10</span> <span style="color: #eeeeee;">||</span> <span style="color: #dfc484;">$b</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">3</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>  
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;true &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #e8ed97;">else</span> 
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;false &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tutorialmelayu.com/web-programming/php/membuat-kiraan-dalam-php-menggunakan-operators-aritmetik-logik/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

