当前位置 : 主页 > 网络编程 > PHP >

php 类定义和类使用实例

来源:互联网 收集:自由互联 发布时间:2021-07-03
?phpclass emp{ var $name; var $address; var $dept; function assign_info($n,$a,$d) { $this-name=$n; $this-state=$a; $this-dept=$d; } function display_info() { echo("pEmployee Name : $this-name"); echo("pState : $this-state"); echo("pDepartme
<?php
class emp
{
   var $name;
   var $address;
   var $dept;
   function assign_info($n,$a,$d)
   {
      $this->name=$n;
      $this->state=$a;
      $this->dept=$d;
   }
   function display_info()
   {
      echo("<p>Employee Name : $this->name");
      echo("<p>State : $this->state");
      echo("<p>Department : $this->dept");
   }
}
$empobj = new emp;
$empobj->assign_info("kaka lname","California","Accounts");
echo("<center><h2>Displaying Employee Information</h2></center>");
echo("<font size=4>");
$empobj->display_info();
echo("</font>");
?>
网友评论