replace with `array_search` and `array_slice`?