What you want is to individually check each element of the array. I mean, it would be something like this:
for ($i=(int)0; $i<count($remetenteArray); $i++){
print ">".$remetenteArray[$i]."< ";
}
I guess you must have tried something like that and then got something like:
PHP Notice: Array to string conversion in ..
Turns out you made a mistake defining the array:
$remetenteArray[] = str_split($remetente, 1);
By placing the opens and closes brackets you have created a array within the other, that is, the first item of it contains the array resulting from the function str_split()
then just remove them the loop will work properly.
But as what you want is to return only the numbers of string within the array, there is not even the need to make this whole juggling, create a function that receives the string and spit out the array desired.
function onlyNumbers($str){
$result=[];
for($i=0; $i<strlen($str); $i++){
$j = substr($str, $i,1);
if ($j>="0" and $j<="9") $result[]=$j;
}
return $result;
}
Thus:
$remetente = "0 A 1 B 2 C 3 D 4";
print_r(onlyNumber($remetente));
Will result in:
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
)
In fact, it was thanks to print_r()
I discovered your mistake. :-)
str_split
turns a string into an array of letters, to iterate on each letter. What is the content of$remetente
? Or you want to print only the letters that are numbers ?– Isac
I want to save in an array only strings that are numbers.
– Lucas Pletsch
But what you got
$remetente
? And what did you like that$remetenteArray[]
had ?– Isac