<?php //比较最大数值 class Math{ public static function Max($num1, $num2){ return $num1 > $num2 ? $num1 : $num2; } } $a = 1000; $b = 5000; echo "显示 $a 和 $b 中的最大值是"; echo Math::Max($a, $b); //返回5000 //类函数,=>,->,::,self,$this用法 class User{ var $userData = array( 'name' => 'zhou_ein', 'gender' => '男', 'age' => 18, ); public static $Data = array( 'name' => 'zhouEin', 'gender' => '男', 'age' => 16, ); public $name = '钢锅'; public static $gender = '男'; var $age = 20; function getData(){ $data[] = $this -> name; $data[] = self :: $gender; $data[] = $this -> age; $data[] = $this -> userData; $data[] = self :: $Data; return $data; } } $data = new User; echo $data -> name; //钢锅 echo User :: $gender; //男 echo $data -> age; //20 var_dump($data -> getData()); //返回所有数组和变量
标签:函数,gender,self,echo,用法,data,age,name From: https://www.cnblogs.com/zhouein/p/18190948