Posts

Showing posts from March 27, 2019

Pagination Function - Can this be shortened or approached differently?

Image
up vote 5 down vote favorite 2 I recently had an interview for a programming job and after the interview I was then asked to create a function with the following brief: The Task: Relating to pagination links: given a page number, a total number of pages, and an amount of 'context' pages, generate the appropriate pagination links. For example, with 9 pages in total and a context of 1 page, you would get the following results for pages 1 to 9: For page 1: 1 2 ... 8 9 For page 2: 1 2 3 ... 8 9 For page 3: 1 2 3 4 ... 8 9 For page 4: 1 2 3 4 5 ... 8 9 For page 5: 1 2 ... 4 5 6 ... 8 9 For page 6: 1 2 ... 5 6 7 8 9 For page 7: 1 2 ... 6 7 8 9 For page 8: 1 2 ... 7 8 9 For page 9: 1 2 ... 8 9 I would like you to write a PHP function with the following signature...