loop van arrays
Ik vroeg me af hoe ik een loop maak voor onderstaande array.
Tot nu toe krijg ik enkel maar de [0] of de [1] array, maar niet elke array na elkaar.
Code (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
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
array(2) {
[0]=> array(11) {
["balloonCapacity"]=> int(4)
["balloonName"]=> string(6) "Ikarus"
["flightDate"]=> string(10) "2021-06-05"
["flightHour"]=> string(8) "20:00:00"
["flightId"]=> int(73)
["flightPeriod"]=> string(2) "PM"
["freeCapacity"]=> int(3)
["locationAddress"]=> string(16) "Luchtvaartstraat"
["locationCity"]=> string(7) "Hasselt"
["locationId"]=> int(18)
["locationName"]=> string(7) "Hasselt"
}
[1]=> array(11) {
["balloonCapacity"]=> int(12)
["balloonName"]=> string(8) "Daedalus"
["flightDate"]=> string(10) "2021-10-03"
["flightHour"]=> string(8) "17:30:00"
["flightId"]=> int(69)
["flightPeriod"]=> string(2) "PM"
["freeCapacity"]=> int(8)
["locationAddress"]=> string(11) "Grote Markt"
["locationCity"]=> string(12) "Sint Niklaas"
["locationId"]=> int(22)
["locationName"]=> string(12) "Sint Niklaas"
}
}
[0]=> array(11) {
["balloonCapacity"]=> int(4)
["balloonName"]=> string(6) "Ikarus"
["flightDate"]=> string(10) "2021-06-05"
["flightHour"]=> string(8) "20:00:00"
["flightId"]=> int(73)
["flightPeriod"]=> string(2) "PM"
["freeCapacity"]=> int(3)
["locationAddress"]=> string(16) "Luchtvaartstraat"
["locationCity"]=> string(7) "Hasselt"
["locationId"]=> int(18)
["locationName"]=> string(7) "Hasselt"
}
[1]=> array(11) {
["balloonCapacity"]=> int(12)
["balloonName"]=> string(8) "Daedalus"
["flightDate"]=> string(10) "2021-10-03"
["flightHour"]=> string(8) "17:30:00"
["flightId"]=> int(69)
["flightPeriod"]=> string(2) "PM"
["freeCapacity"]=> int(8)
["locationAddress"]=> string(11) "Grote Markt"
["locationCity"]=> string(12) "Sint Niklaas"
["locationId"]=> int(22)
["locationName"]=> string(12) "Sint Niklaas"
}
}
Ik weet niet als dat van belang is, maar de data komt van Json en wordt via een Cronjob in Plesk opgeroepen (de API Key even verwijderd ;-) .
Code (php)
1
$params = (array) json_decode(file_get_contents("https://quick-release-play-endpoint-t4s7w6vxjq-ew.a.run.app/get_flights_play?key="), true);
Wie kan mij helpen?
Gewijzigd op 17/06/2021 16:02:21 door Bart Raymakers
Ik heb meerdere handleidingen geraadpleegd en al tientallen scenario’s uitgetest. Maar zonder resultaat. Vandaar dus ook mijn vraag hier post,
Code (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
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
<?php
$params = [
[
"balloonCapacity" => 4,
"balloonName" => "Ikarus",
"flightDate" => "2021-06-05",
"flightHour" => "20:00:00",
"flightId" => 73,
"flightPeriod" => "PM",
"freeCapacity" => 3,
"locationAddress" => "Luchtvaartstraat",
"locationCity" => "Hasselt",
"locationId" => 18,
"locationName" => "Hasselt"
],
[
"balloonCapacity" => 12,
"balloonName" => "Daedalus",
"flightDate" => "2021-10-03",
"flightHour" => "17:30:00",
"flightId" => 69,
"flightPeriod" => "PM",
"freeCapacity" => 8,
"locationAddress" => "Grote Markt",
"locationCity" => "Sint Niklaas",
"locationId" => 22,
"locationName" => "Sint Niklaas"
]
];
echo '<pre>' . print_r( $params, TRUE ) . '</pre>';
foreach ( $params as $param )
{
echo '<p>';
foreach ( $param as $key => $value )
{
echo $key . ' = ' . $value . '<br />';
}
echo '</p>';
}
?>
$params = [
[
"balloonCapacity" => 4,
"balloonName" => "Ikarus",
"flightDate" => "2021-06-05",
"flightHour" => "20:00:00",
"flightId" => 73,
"flightPeriod" => "PM",
"freeCapacity" => 3,
"locationAddress" => "Luchtvaartstraat",
"locationCity" => "Hasselt",
"locationId" => 18,
"locationName" => "Hasselt"
],
[
"balloonCapacity" => 12,
"balloonName" => "Daedalus",
"flightDate" => "2021-10-03",
"flightHour" => "17:30:00",
"flightId" => 69,
"flightPeriod" => "PM",
"freeCapacity" => 8,
"locationAddress" => "Grote Markt",
"locationCity" => "Sint Niklaas",
"locationId" => 22,
"locationName" => "Sint Niklaas"
]
];
echo '<pre>' . print_r( $params, TRUE ) . '</pre>';
foreach ( $params as $param )
{
echo '<p>';
foreach ( $param as $key => $value )
{
echo $key . ' = ' . $value . '<br />';
}
echo '</p>';
}
?>
Bedankt voor jouw reactie. Maar de data wordt via JSon gegenereerd (url). Het is de bedoeling dat te kunnen gebruiken, niet de data opnieuw in php in te voeren. Dus ik moet die data misschien eerst in een object steken? Nog nooit eerder gedaan.
Dus controleer wat daar in zit.
Begin op regel 31 van mijn voorbeeld.
Bart Raymakers op 17/06/2021 16:53:00:
Het is de bedoeling dat te kunnen gebruiken, niet de data opnieuw in php in te voeren.
Waarvoor wil je de data gebruiken?
Bart Raymakers op 17/06/2021 16:32:46:
Ik heb meerdere handleidingen geraadpleegd en al tientallen scenario’s uitgetest.
Kan je er eentje posten?
Oké, de loop werkt, Bedankt Adoptive Solution! Ik was het blijkbaar vééél te ver aan't zoeken.