-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_books.php
More file actions
60 lines (56 loc) · 1.35 KB
/
debug_books.php
File metadata and controls
60 lines (56 loc) · 1.35 KB
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
59
60
<?php
$friends = [
[
'name' => 'Oliver',
'books' => [
'Ansible for DevOps',
'Servers for hackers',
]
],
[
'name' => 'Barry',
'books' => [
'Working effectively with unit tests',
'50 quick ideas for your tests',
],
],
[
'name' => 'Jessica',
'books' => [
'Understanding the 4 rules of simple design',
'Principles of package design',
],
],
[
'name' => 'Clark',
'books' => [
'Selling test driven projects',
],
]
];
function searchByName($friends, $name) {
$filtered = [];
foreach ($friends as $friend) {
if (strpos($friend['name'], $name) !== false) {
$filtered[] = $friend;
}
}
return $filtered;
}
do {
echo '1. Show friends books', PHP_EOL;
echo '2. Search by name', PHP_EOL;
echo '3. Exit', PHP_EOL;
$option = fgets(STDIN);
switch ($option) {
case 1:
// TODO: Implement this one later...
break;
case 2:
//It's not returning an array with the names that are similar to $name
echo 'Please enter a name: ';
$name = trim(fgets(STDIN));
var_dump(searchByName($friends, $name));
break;
}
} while ($option != 3);