Skip to content

Simple PHP class to convert conventional arrays into circular arrays.

Notifications You must be signed in to change notification settings

alesinicio/circularArray

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

circularArray

Simple PHP class to convert conventional arrays into circular arrays.

Sometimes we need to use arrays in a non-conventional way, in a circular manner where the array wraps around itself. Although it is not particularly difficult to implement it in your own code, it may be even simpler to use something that is already done, functional and tested.

Indexed and associative arrays

You can use both indexed and associative arrays. When you use associative arrays, this class WILL NOT make any kind of sorting.

Methods

There are probably enough methods to meet your needs. You can create the circular array, get the value of the current position, get the index of the current position, advance, rewind and reset the pointer. There are also some methods that wrap two methods in one call, like "advance and give me the new value".

Easy to use

Example file is provided. The basic usage is: ``` $arrExample = [1,2,3,4]; $arrCircular = new circularArray($arrExample);

for ($i=0; $i<10; $i++) { echo $arrCircular->getCurrentValue(); $arrCircular->next(); }


The expected output is "1234123412" (walk 10 times through the "1,2,3,4" array).

About

Simple PHP class to convert conventional arrays into circular arrays.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages