[英]Why is my case within the switch query not always executed?
My Code:我的代码:
for ($i = 0, $anzZeilen = count($zeilen); $i < $anzZeilen; $i++) {
switch ($zeilen[$i]['satzart']) {
case 10: // Bundesland
satz10($db, $zeilen[$i]);
break;
case 40: // Landkreis
satz40($db, $zeilen[$i]);
break;
case 60: // Kommune
satz60($db, $zeilen[$i]);
break;
}
}
My test output (a small excerpt):我的测试 output(一小段摘录):
int(60)
Quelle :Ofterdingen | Rohdaten Ofterdingen | bereinigt :Ofterdingen | ohne sorbisch :Ofterdingen | ohne , :Ofterdingen
int(60)
Quelle :Rottenburg am Neckar, Stadt |
int(60)
Quelle :Tübingen, Universitätsstadt |
int(60)
Quelle :Ammerbuch | Rohdaten Ammerbuch | bereinigt :Ammerbuch | ohne sorbisch :Ammerbuch | ohne , :Ammerbuch
The corresponding variable is integer and 60. |对应的变量是 integer 和 60。 dump($zeilen[$i]['satzart'])转储($zeilen[$i]['satzart'])
And I have no idea why the function satz60() is not executed.而且我不知道为什么不执行 function satz60() 。 (This can be seen in the test output, that no further values are output.) (这可以在测试 output 中看到,没有进一步的值是 output。)
It is not relevant because I did a test output before calling satz60(), but this is what the code of the called function looks like including auxiliary outputs.这是不相关的,因为我在调用 satz60() 之前做了一个测试 output,但这就是所谓的 function 的代码看起来像包括辅助输出。
function satz60(PDO $db, array $zeilen)
{
$bundeslandDestatis = (int) substr($zeilen['region'],0,2);
$landkreisDestatis = (int) substr($zeilen['region'],2,3);
$gebietsForm = (int) $zeilen['schluessel'];
if (in_array($gebietsForm, [60,61,62,63,64])) {
$gemeindeName = bereinigeGebietsname($zeilen['bezeichnung1']);
echo ' Rohdaten '.$zeilen['bezeichnung1'].' | bereinigt :'.$gemeindeName.' | ohne sorbisch :';
// Namenszusätze entfernen - sorbisch
if (strpos($gemeindeName, ' / ') > 0 ) {
$gemeindeName = substr($gemeindeName,0,strpos($gemeindeName, ' / ')) ;
}
echo $gemeindeName.' | ohne , :';
// Namenszusätze nach dem , entfernen
if (strpos($gemeindeName, ', ') > 0 ) {
$gemeindeName = substr($gemeindeName,0,strpos($gemeindeName, ', ')) ;
}
echo $gemeindeName.'<br>';
$query = 'SELECT * FROM `destatis_landkreis` WHERE `landkreis_destatis` = \''.$landkreisDestatis.'\' AND `bundesland_destatis`= \''.$bundeslandDestatis.'\'';
$select = $db->query($query);
$landkreis = $select->fetch();
if (!$landkreis['kreisfrei']) {
$k = 1;
while ($k < 246) {
$spalte = 'LKM'.$k;
if (empty($landkreis[$spalte])) {
$sql2 = 'UPDATE `destatis_landkreis` SET `LKM'.$k.'`= ? WHERE `landkreis_destatis`= ? AND `bundesland_destatis`=?';
$statement = $db->prepare($sql2);
$statement->execute([$gemeindeName,$landkreisDestatis,$bundeslandDestatis]);
$k = 246;
}
$k++;
}
}
}
}
Extract from $zeilen - raw data从 $zeilen 中提取 - 原始数据
6020210131084160315002Ofterdingen 64 000000015150000000518200000002581 72131 2886270766417290
6020210131084160365003Rottenburg am Neckar, Stadt 67 000000142260000004384300000021763 72108 2886270666417290
6020210131084160410041Tübingen, Universitätsstadt 67 000000108060000009150600000043546 72070***** 2886270766417290
6020210131084160480048Ammerbuch 64 000000048040000001130200000005610 72119***** 2886270766417290
My error is in the line我的错误就在这条线上
if (in_array($gebietsForm, [60,61,62,63,64])) {
In the source file there are further area forms, which did not appear in the file description.在源文件中还有forms,文件描述中没有出现。
So it must be -without further check-:所以它必须 - 无需进一步检查 - :
if (in_array($gebietsForm, [60,61,62,63,64,65,66,67,68,69])) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.