<?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; function dalam php</title>
	<atom:link href="http://www.tutorialmelayu.com/tag/function-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>menulis function php sendiri</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/menulis-function-php-sendiri</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/menulis-function-php-sendiri#comments</comments>
		<pubDate>Sun, 29 Mar 2009 13:02:09 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[belajar php melayu mudah]]></category>
		<category><![CDATA[function dalam php]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=104</guid>
		<description><![CDATA[Jika anda masih baru dengan function php, mungkin anda perlu merujuk tutorial ini dahulu. Untuk menambahkan fungsi dan menjadikan function itu lebih dinamik, kita boleh menambah parameter pada function kita. Function NamaSaya() di bawah memberi output yang berbeza untuk input yang berbeza. &#60;?php //function function UcapSelamat&#40;$nama&#41; &#123; echo &#34;Selamat Datang ke Tutorial Melayu, $nama! &#60;br&#62;&#34;; [...]]]></description>
			<content:encoded><![CDATA[<p>Jika anda masih baru dengan function php, mungkin anda perlu merujuk <a href="http://www.tutorialmelayu.com/web-programming/menulis-function-php-sendiri-asas">tutorial</a> ini dahulu.</p>
<p><span id="more-104"></span></p>
<p>Untuk menambahkan fungsi dan menjadikan function itu lebih dinamik, kita boleh menambah parameter pada function kita.</p>
<p>Function NamaSaya() di bawah memberi output yang berbeza untuk input yang berbeza.</p>

<div class="wp_codebox"><table><tr id="p1043"><td class="code" id="p104code3"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//function</span>
<span style="color: #dfc484; font-weight: bold;">function</span> UcapSelamat<span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$nama</span><span style="color: #eeeeee;">&#41;</span> <span style="color: #eeeeee;">&#123;</span>
    <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Selamat Datang ke Tutorial Melayu, <span style="color: #dfc484; font-weight: bold;">$nama</span>! &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #eeeeee;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//contoh penggunaan</span>
UcapSelamat<span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">&quot;mdpai&quot;</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
UcapSelamat<span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">&quot;wan mohd fairuz&quot;</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//contoh function lain</span>
<span style="color: #dfc484; font-weight: bold;">function</span> Tambah<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: #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;">$a</span> dan <span style="color: #dfc484; font-weight: bold;">$b</span> ialah <span style="color: #dfc484; font-weight: bold;">$c</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//contoh penggunaan </span>
Tambah<span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">2</span><span style="color: #eeeeee;">,</span> <span style="color: #ff8400;">3</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
Tambah<span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">5</span><span style="color: #eeeeee;">,</span> <span style="color: #ff8400;">2</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Dengan menggunakan function, kita bukan hanya boleh memproses nilai yang terdapat di parameter tetapi kita juga boleh memulangkan nilai tersebut untuk digunakan dalam code seterusnya. Lihat contoh:</p>

<div class="wp_codebox"><table><tr id="p1044"><td class="code" id="p104code4"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//contoh functio</span>
<span style="color: #dfc484; font-weight: bold;">function</span> Tambah<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: #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;">return</span> <span style="color: #dfc484;">$c</span>
<span style="color: #eeeeee;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//contoh penggunaan </span>
<span style="color: #dfc484;">$hasil</span> <span style="color: #eeeeee;">=</span> Tambah<span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">2</span><span style="color: #eeeeee;">,</span> <span style="color: #ff8400;">3</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$hasil</span> <span style="color: #eeeeee;">&gt;</span><span style="color: #ff8400;">10</span><span style="color: #eeeeee;">&#41;</span>
   <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Lebih dari 10 &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;Kurang dari 10 &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>Function merupakan satu alat yang amat berkuasa di dalam PHP. Ianya digunakan dengan meluas di dalam komuniti PHP. Jadi pastikan anda betul-betul faham contoh yang diberikan.</p>
<p>Selamat mencuba!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialmelayu.com/web-programming/php/menulis-function-php-sendiri/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

