-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patharrays2.php
41 lines (31 loc) · 1.02 KB
/
arrays2.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
<?php
$arr = ['Peter', 'Carol', 'Bruce'];
//$v1 = $arr[0];
//$v2 = $arr[1];
//$v3 = $arr[3];
//list($v1, $v2, $v3) = $arr;
[$v1, $v2, $v3, $v4] = $arr;
echo $v1."\n";
echo $v2."\n";
echo $v3."\n";
echo $v4."\n";
$posts = [
['date' => time(), 'author' => 'Peter Parker', 'content' => 'Bla bla bla1'],
['date' => time(), 'author' => 'Tony Stark', 'content' => 'Bla bla bla2'],
['date' => time(), 'author' => 'Carol Danvers', 'content' => 'Bla bla bla3'],
['date' => time(), 'author' => 'Natasha Romanov', 'content' => 'Bla bla bla4'],
];
echo $posts[0]['author']."\n";
foreach($posts as $post) {
echo $post['author'].', '.$post['content']."\n";
}
echo "\n\n";
foreach($posts as ['author' => $author, 'content' => $content]) {
echo $author.', '.$content."\n";
}
// Sourcecode in Externe Dateien lässt sich einfacher wiederverwenden
require_once 'includes/config.php';
require_once 'includes/functions.php';
foreach(getAllUsers($dbh) as ['firstname' => $fn, 'lastname' => $ln]) {
echo $fn.', '.$ln."\n";
}