Bug #80740 [NEW]: Possible "in_array" bug
| From: | celestinoxp at hotmail dot com | Date: | Fri, 12 Feb 2021 16:07:33 +0000 |
| Subject: | Bug #80740 [NEW]: Possible "in_array" bug | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-232098@lists.php.net to get a copy of this message | ||
From: celestinoxp at hotmail dot com
Operating system: Windows 10
PHP version: 8.0Git-2021-02-12 (snap)
Package: Unknown/Other Function
Bug Type: Bug
Bug description:Possible "in_array" bug
Description:
------------
I have a code to insert delays of numbers in a mysql table, however
values are not correct.
I think my code is correct, so, assuming that, i think problem is in php
or mysql, it´s for that i need help to check if is a bug in php or
not...
I have a mysql table with lotto numbers (n1, n2, n3...) and delays
(n1_ausencias, n2_ausencias...)
my script is to update values (initial 0) to delay values in
(n1_ausencias, n2_ausencias, n3_ausencias...)
printscreen: https://i.stack.imgur.com/GBZQx.png
Test script:
---------------
<?php
set_time_limit(0);
include "../ligar_bd.php";
$i = 0;
$result = mysqli_query($db, "SELECT
id, data, n1,
n2, n3,
n4, n5, ns FROM tbl_todos WHERE
nome_do_jogo = 'totoloto'
ORDER BY tbl_todos.data DESC;");
$f = mysqli_num_rows($result);
while ($dados = mysqli_fetch_array($result)){
$chave_bd = array($dados['n1'], $dados['n2'], $dados['n3'],
$dados['n4'], $dados['n5']);
$conta = -1;
++$i;
$n1_encontrou = 0;
$n2_encontrou = 0;
$n3_encontrou = 0;
$n4_encontrou = 0;
$n5_encontrou = 0;
$ns_encontrou = 0;
$result2 = mysqli_query($db, "SELECT id, data, n1,
n2, n3,
n4, n5, ns FROM tbl_todos WHERE
nome_do_jogo = 'totoloto'
ORDER BY tbl_todos.data DESC LIMIT $i, $f;");
while ($dados2 = mysqli_fetch_array($result2)){
++$conta;
$n1 = $dados2['n1'];
$n2 = $dados2['n2'];
$n3 = $dados2['n3'];
$n4 = $dados2['n4'];
$n5 = $dados2['n5'];
$ns = $dados2['ns'];
if (in_array($n1, $chave_bd) and ($n1_encontrou == 0)){
$n1_encontrou = 1;
$n1_pos = $conta;
}
if (in_array($n2, $chave_bd) and ($n2_encontrou == 0)){
$n2_encontrou = 1;
$n2_pos = $conta;
}
if (in_array($n3, $chave_bd) and ($n3_encontrou == 0)){
$n3_encontrou = 1;
$n3_pos = $conta;
}
if (in_array($n4, $chave_bd) and ($n4_encontrou == 0)){
$n4_encontrou = 1;
$n4_pos = $conta;
}
if (in_array($n5, $chave_bd) and ($n5_encontrou == 0)){
$n5_encontrou = 1;
$n5_pos = $conta;
}
if ($ns == $dados['ns'] and $ns_encontrou == 0){
$ns_encontrou = 1;
$ns_pos = $conta;
}
//Se encontrou ausencias de todos, não precisa perder mais tempo a
percorrer toda a tabela
if ($n1_encontrou == 1 and $n2_encontrou == 1 and $n3_encontrou == 1
and $n4_encontrou == 1 and $n5_encontrou == 1 and $ns_encontrou == 1){
break;
}
} //fecha while dados2
$atualiza = mysqli_query($db, "UPDATE tbl_todos SET n1_ausencias =
$n1_pos, n2_ausencias = $n2_pos, n3_ausencias = $n3_pos,
n4_ausencias = $n4_pos, n5_ausencias = $n5_pos, ns_ausencias
=
$ns_pos WHERE tbl_todos.id = $dados[id];");
} //fecha while dados
?>
Expected result:
----------------
correct delay values
Actual result:
--------------
incorrect delay values
printscreen: https://i.stack.imgur.com/GBZQx.png
--
Edit bug report at https://bugs.php.net/bug.php?id=80740&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80740&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80740&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80740&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80740&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80740&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80740&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80740&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80740&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80740&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80740&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80740&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80740&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80740&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80740&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80740&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80740&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80740&r=mysqlcfg