-
Notifications
You must be signed in to change notification settings - Fork 0
/
ph
58 lines (49 loc) · 1.28 KB
/
ph
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
// Define an associative array of countries and their capitals
$countries = array(
"USA" => "Washington D.C.",
"France" => "Paris",
"Japan" => "Tokyo",
"India" => "New Delhi"
);
// Loop through the associative array and print each country and its capital
foreach ($countries as $country => $capital) {
echo "Country: $country, Capital: $capital <br>";
}
// Define a function to check if a number is prime
function isPrime($num) {
if ($num <= 1) {
return false;
}
for ($i = 2; $i <= sqrt($num); $i++) {
if ($num % $i == 0) {
return false;
}
}
return true;
}
// Call the function to check if a number is prime
$number = 17;
if (isPrime($number)) {
echo "$number is a prime number. <br>";
} else {
echo "$number is not a prime number. <br>";
}
// Define a class with properties and methods
class Animal {
public $name;
public $sound;
public function makeSound() {
echo $this->name . " makes a sound: " . $this->sound . "<br>";
}
}
// Create objects of the class and call the method
$animal1 = new Animal();
$animal1->name = "Dog";
$animal1->sound = "Woof";
$animal1->makeSound();
$animal2 = new Animal();
$animal2->name = "Cat";
$animal2->sound = "Meow";
$animal2->makeSound();
?>