How Does Pagination Work?

Is there a controller file that partitions the $product array that the products pull information from? Because I looked into the content of the $products array per page and the only products that are in that array are the ones currently being shown on the page, not the products for everything in that category/search.

I'd be grateful for any point in the right direction, thanks.

The system checks request parameters and retrieve from database only required items taking into account page number, items per page, etc