COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
echo
$myarr[2];
echo
"<br>";
$myarrs=array("first", "last", "company");
echo
$myarrs[2];
?>
</BODY>
</HTML>
Neáu nhö baïn khai baùo maûng hai chieàu, thì cuù phaùp khai baùo nhö sau:
$myarrs[][]=array(2,3);
Chaúng haïn khai baùo nhö ví duï 2-7 (arrays.php):
<HTML>
<HEAD>
<TITLE>::Welcome to PHP</TITLE>
</HEAD>
<BODY>
<h4>Array two demenssions</h4>
<?php
$myarrs[][]=array(2,3);
$myarrs[0][0]="Number
00";
$myarrs[1][0]="Number
10";
$myarrs[0][1]="Number
01";
$myarrs[1][1]="Number
11";
$myarrs[0][2]="Number
02";
$myarrs[1][2]="Number
13";
echo
$myarrs[0][2];
echo
"<br>";
?>
</BODY>
</HTML>
3.5.
Kieåu ñoái töôïng
Ñeå khai baùo ñoái töôïng, baïn söû duïng khaùi nieäm class nhö trong ngoân ngöõ laäp trình C
hay java, ngoaøi ra phöông thöùc trong PHP ñöôïc bieát ñeán nhö moät haøm. Ñieàu naøy coù
nghóa laø töø khoaù laø function.
Neáu haøm coù teân truøng vôùi teân cuûa class thì haøm ñoù ñöôïc goïi laø constructor. Chaúng
haïn, chuùng ta khai baùo class vaø khôûi taïo chuùng thì töï ñoäng constructor ñöôïc goïi moãi
khi ñoái töôïng khôûi taïo, sau ñoù goïi haøm trong class ñoù nhö ví duï 2-8 (object.php).
<HTML>
<HEAD>
<TITLE>::Welcome to PHP</TITLE>
</HEAD>
<BODY>
<h4>Object</h4>
<?php
class clsA
{
function clsA()
{
echo "I am the constructor of A.<br />\n";
}
function B()
Giaùo vieân: Phaïm Höõu Khang