-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
45 lines (37 loc) · 1.06 KB
/
functions.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
function display_recipe(array $recipe) : string
{
$recipe_content = '';
if ($recipe['is_enabled']) {
$recipe_content = '<article>';
$recipe_content .= '<h3>' . $recipe['title'] . '</h3>';
$recipe_content .= '<div>' . $recipe['recipe'] . '</div>';
$recipe_content .= '<i>' . $recipe['author'] . '</i>';
$recipe_content .= '</article>';
}
return $recipe_content;
}
function display_author(string $authorEmail, array $users) : string
{
for ($i = 0; $i < count($users); $i++) {
$author = $users[$i];
if ($authorEmail === $author['email']) {
return $author['full_name'] . '(' . $author['age'] . ' ans)';
}
}
}
function get_recipes(array $recipes, int $limit) : array
{
$valid_recipes = [];
$counter = 0;
foreach($recipes as $recipe) {
if ($counter == $limit) {
return $valid_recipes;
}
if ($recipe['is_enabled']) {
$valid_recipes[] = $recipe;
$counter++;
}
}
return $valid_recipes;
}