So given this array:
$stack = [
100,
200,
300,
400,
500,
600,
700
]
What is the best way, given some arbitrary number, for example $needle = 78
, to find 'nearest' number from the stack. In this case it would be 100.
I have algorithm in mind, where I loop through all numbers, and do determine it eventually.
But this for some reason feels, like it has some nice one liner solution that I am just not aware of. So is my feeling correct, is there such one liner?