PHP is not strongly typed
$IdUF = substr($rowData['IdMunicipio'],0,2)
returns a string
but case $IdUF
is used in an operation as sum its value
will be converted so if:
<?php
$IdUF = substr($rowData['IdMunicipio'],0,2);
//$IdUF = "10" - Str
//Quando fazemos alguma operação
$IdUF++;
//$IdUF = 11 - Int
Now if the problem is when saving in the bank the solution depends on how you are implemented.
A solution to force the value is to perform the cast or conversion, between the solutions you could:
<?php
$IdUF = (int)substr($rowData['IdMunicipio'],0,2);
//ou
$IdUF = intval(substr($rowData['IdMunicipio'],0,2));
//Dessa forma o $IdUF será sempre inteiro, caso seja retornando
//um valor que ele não consiga converter como "olá"
// o valor de $IdUF será 0.
subst
returns anotherstring
, if you are returning the value properly, just convert toint
with the functionintval
or add(int)
in front of the function.– Woss
It’s like @Andersoncarloswoss said. In your case, you should convert the integer to a string using (string) before
$IdUF = substr((string)$rowData['IdMunicipio'], 0, 2)
– Not The Real Hemingway
I appreciate the tips, I’ll run some tests.
– adventistapr