Page 355 - CITS - CSA - TP (Volume 1) - Hindi
P. 355
कंप्यूटर सॉफ्टवेयर एप्लीकेशन- CITS
III ऑ े पर पुनरावृि (Iterating over Objects)
1 टे एिडटर ओपन करे
2 िन िल खत कोड िलख
<html >
<head>
<title> Iterators </title>
</head>
<body>
<?php
class User
{
public $name;
public $age;
public function __construct($name, $age)
{
$this->name = $name;
$this->age = $age;
}
}
$users = [
new User(“Alice”, 25),
new User(“Bob”, 30),
];
// Using foreach loop and custom IteratorAggregate:
class UserCollection implements IteratorAggregate
{
private $users;
public function __construct(array $users)
{
$this->users = $users;
}
public function getIterator()
339
CITS : IT & ITES - कं ूटर सॉ वेयर ए ीके शन - अ ास 60

