WPDev.one
Core Function
View Source on Trac ↗

wp_find_hierarchy_loop_tortoise_hare()

wp_find_hierarchy_loop_tortoise_hare( mixed $callback, mixed $start, mixed $override = array(), mixed $callback_args = array(), mixed $_return_loop = false )

Uses the "The Tortoise and the Hare" algorithm to detect loops.

Parameters 4 required

Name / Type Description
$callback
callable

Function that accepts ( ID, callback_arg, ... ) and outputs parent_ID.

Required
$start
int

The ID to start the loop check at.

Required
array

$override Optional. An array of ( ID => parent_ID, ... ) to use instead of $callback. Default empty array.

Required
$callback_args
array

Optional. Additional arguments to send to $callback. Default empty array.

bool

$_return_loop Optional. Return loop members or just detect presence of loop? Only set to true if you already know the given $start is part of a loop (otherwise the returned array might include branches). Default false.

Required

Return Value

(mixed)
mixed Scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if $_return_loop

Function Information

Since Version
3.1.0
Source File
wp-includes/functions.php
Advertisement