-1

I have some code that is selecting a log entry (in a loop) to get the most recent inventory quantities of an item. I would like a way to always get the last occurrence of an integer in a string that will look slightly different on each iteration through the loop:

Inventory changed from 13 to 12
Inventory changed from 12 to 11
Inventory changed from 11 to 10
Inventory changed from 10 to 9
Inventory changed from 9 to 8

For each of these strings, I'll always need to return the last number(s). So if I have "10 to 11" i'll need "11", or if I have "9 to 8" i'll need "8".

I've not found a way to do this that will account for the multitude of ways that those integers will show up in that string (i.e., changed from 123 to 153, 8 to 9, 0 to 1, etc.)

Any advice would be greatly appreciated.

1 Answers1

0

You should use explode

$mystring="Inventory changed from 13 to 12";
$pieces=explode(" ",$mystring);

//$pieces["Inventory","changed","from","13","to","12"];
echo $pieces[5]; //it will print 12.
Andrea
  • 99
  • 1
  • 1
  • 9