I have the following working code:
$nif = 'A12345678';
$even = $nif[2] + $nif[4] + $nif[6];
for ($i = 1; $i < 8; $i += 2)
{
echo $nif[$i];
$even += substr((2 * $nif[$i]), 0, 1) + substr((2 * $nif[$i]), 1, 1);
}
Output for PHP 7.0.14
1357
Output for PHP 7.1
1<br />
<b>Warning</b>: A non-numeric value encountered in <b>[...][...]</b> on line <b>22</b><br />
3<br />
<b>Warning</b>: A non-numeric value encountered in <b>[...][...]</b> on line <b>22</b><br />
57
Now if I change the value of $nif
to:
$nif = 'A52545678';
The output for 7.1 would be:
5557
Already tried passing a normal variable to substr()
but that's not the problem:
$a = $nif[$i];
$even += substr((2 * $a), 0, 1) + substr((2 * $a), 1, 1);
Why is PHP 7.1 or substr()
from PHP 7.1 treating numeric values in the range '0-4'
as non-numeric values?