<?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; asas php</title>
	<atom:link href="http://www.tutorialmelayu.com/tag/asas-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>PHP array</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/php-array</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/php-array#comments</comments>
		<pubDate>Fri, 03 Apr 2009 21:20:53 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[asas php]]></category>
		<category><![CDATA[belajar php mudah]]></category>
		<category><![CDATA[php array]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=120</guid>
		<description><![CDATA[Array adalah satu struktur yang boleh menyimpan satu atau lebih nilai. Anda boleh andaikan ia sebagai satu variable yang boleh menyimpan pelbagai nilai serentak. Ia sesuai digunakan jika anda ingin menyimpan beberapa nilai mengikut kumpulan yang sama. Untuk contoh, kita andaikan kita mahu menyimpan nama-nama pelajar di dalam array $pelajar. &#60;?php $pelajar&#91;0&#93; = &#34;abu&#34;; $pelajar&#91;1&#93; [...]]]></description>
			<content:encoded><![CDATA[<p>Array adalah satu struktur yang boleh menyimpan satu atau lebih nilai. Anda boleh andaikan ia sebagai satu variable yang boleh menyimpan pelbagai nilai serentak. Ia sesuai digunakan jika anda ingin menyimpan beberapa nilai mengikut kumpulan yang sama. Untuk contoh, kita andaikan kita mahu menyimpan nama-nama pelajar di dalam array $pelajar.</p>
<p><span id="more-120"></span></p>

<div class="wp_codebox"><table><tr id="p1204"><td class="code" id="p120code4"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">0</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;abu&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">1</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;bedah&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">2</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;kasim&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">3</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;husin&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#91;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;mdpai&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#91;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;mirul&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//output</span>
<span style="color: #dfc484;">print_r</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Perhatikan bahawa nombor indeks sesuatu array bermula dari 0. Jadi, $pelajar[0] merujuk kepada nilai pertama array $pelajar, manakala $pelajar[3] merujuk kepada nilai ke empat array ini. Jika kita tidak memasukkan apa-apa nilai indeks ke dalam array tersebut, (seperti contoh terakhir di atas) secara automatik, nilai tersebut akan dimasukkan ke nombor indeks terakhir yang kosong. Dalam contoh ini, mdpai akan menjadi nilai ke lima array $pelajar manakala mirul nilai ke enam array $pelajar.</p>
<p>Setiap ahli array boleh dianggap sebagai variable yang berasingan. Lihat contoh di bawah yang menyimpan markah-markah seorang pelajar di dalam satu array dan kemudian mengira purata markah pelajar tersebut.</p>

<div class="wp_codebox"><table><tr id="p1205"><td class="code" id="p120code5"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">0</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">85</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">1</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">91</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">2</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">50</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #dfc484;">$purata</span> <span style="color: #eeeeee;">=</span> <span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">0</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">+</span> <span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">1</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">+</span> <span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">2</span><span style="color: #eeeeee;">&#93;</span><span style="color: #eeeeee;">&#41;</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;purata markah <span style="color: #dfc484; font-weight: bold;">$purata</span> &quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Terdapat satu lagi jenis array yang sering digunakan iaitu associative array. Untuk array jenis ini, kita bagaikan memberikan nama untuk setiap ahli array tersebut. Lihat contoh di bawah untuk lebih memahami konsep associative array.</p>

<div class="wp_codebox"><table><tr id="p1206"><td class="code" id="p120code6"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">&quot;matematik&quot;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">85</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">&quot;fizik&quot;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">91</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">&quot;elektrik&quot;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">50</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #dfc484;">$purata</span> <span style="color: #eeeeee;">=</span> <span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">&quot;matematik&quot;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">+</span> <span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">&quot;fizik&quot;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">+</span> <span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">&quot;elektrik&quot;</span><span style="color: #eeeeee;">&#93;</span><span style="color: #eeeeee;">&#41;</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;purata markah <span style="color: #dfc484; font-weight: bold;">$purata</span> &quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<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/php-array/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

