-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforeach_books.php
45 lines (37 loc) · 982 Bytes
/
foreach_books.php
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
<?php
$books = array(
'The Hobbit' => array(
'published' => 1937,
'author' => 'J. R. R. Tolkien',
'pages' => 310
),
'Game of Thrones' => array(
'published' => 1996,
'author' => 'George R. R. Martin',
'pages' => 835
),
'The Catcher in the Rye' => array(
'published' => 1951,
'author' => 'J. D. Salinger',
'pages' => 220
),
'A Tale of Two Cities' => array(
'published' => 1859,
'author' => 'Charles Dickens',
'pages' => 544
)
);
foreach ($books as $title => $book ) {
if ($book['published'] > 1950) {
echo "$title \n";
foreach ($book as $detail => $info) {
echo "{$detail}: {$info}\n";
// echo "---------------\n";
}
}
}
foreach ($books as $title => $book) {
if ($book['published'] > 1950) {
echo "$title - It was published {$book['published']} author name is {$book['author']} and number of pages are {$book['pages']}!\n";
}
}