Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Detecting cyclic arrays in PHP

This repository contains the code snippets from the accompanying blog post: https://hbgl.dev/detecting-cyclic-arrays-in-php-a-new-approach/

The file functions.php contains are a couple of functions that can detect cyclic arrays to various degrees of success. If you are just looking for a good working implementation, use is_cyclic_count.

Running tests

composer run test

Please note that the test case Is cyclic marker with data set "Bomb" is intended to fail. I left it in there to illustrate that the particular function does not work correctly.

Running benchmarks

composer run bench

The benchmarks paint a clear picture. The winner is the count variant, especially when it comes to larger arrays. I also benchmarked the marker variant for illustration purposes, even though the implementation is fundamentally broken (see why). Benchmarks were only run on a subset of arrays that can be successfully checked by all implementations.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages