时间:2019-07-27 12:28 编辑:
本篇文章给大家带来的内容是关于php中Iterator迭代对象属性的用法介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
foreach用法和之前的数组遍历是一样的,只不过这里遍历的key是属性名,value是属性值。在类外部遍历时,只能遍历到public属性的,因为其它的都是受保护的,类外部不可见。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class HardDiskDrive {
class
HardDiskDrive {
public $brand;
public
$brand
;
public $color;
$color
public $cpu;
$cpu
public $workState;
$workState
protected $memory;
protected
$memory
protected $hardDisk;
$hardDisk
private $price;
private
$price
public function __construct($brand, $color, $cpu, $workState, $memory, $hardDisk, <code class="php variable" style="padding: 2px 4px; font-size: 13px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; margin: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; left: auto !important; line-height: 1.5em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-
function
__construct(
,
php中Iterator迭代对象属性的用法介绍
时间:2019-07-27 12:28 编辑:
本篇文章给大家带来的内容是关于php中Iterator迭代对象属性的用法介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
foreach用法和之前的数组遍历是一样的,只不过这里遍历的key是属性名,value是属性值。在类外部遍历时,只能遍历到public属性的,因为其它的都是受保护的,类外部不可见。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
classHardDiskDrive {public$brand;public$color;public$cpu;public$workState;protected$memory;protected$hardDisk;private$price;publicfunction__construct($brand,$color,$cpu,$workState,$memory,$hardDisk,<code class="php variable" style="padding: 2px 4px; font-size: 13px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 4px; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; margin: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; left: auto !important; line-height: 1.5em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-