I have a for loop designed to extract all the numbers from varying strings I supply to it. I am saving the extracted numbers in an array. My code is as follows:
$length = strlen($RouteString);
$data = [];
$index = 0;
for($i = 0; $i < $length; $i++)
{
$j = 1;
$count = 0;
while(is_numeric(substr($RouteString,$i,$j)) == true)
{
$data[$index] = substr($RouteString,$i,$j);
$j = $j+1;
}
if(is_numeric(substr($RouteString,$i,1)) == true)
{
$index = $index + 1;
}
}
$Routestring is set as: "B12-1234-U102-D4-11-19-E" and should give the results of $data=[12,1234,102,4,11,19] but instead it gives $data=[12,2,1234,234,34,4,102,02,2,4,11,1,19,9].
I have tried fixing the problem by adjusting the $index but it doesn't work. I can't figure out how to fix this.
Any advice would be greatly appreciated