Skip to content

Instantly share code, notes, and snippets.

@tablatronix
Last active August 29, 2015 13:57
Show Gist options
  • Save tablatronix/9766306 to your computer and use it in GitHub Desktop.
Save tablatronix/9766306 to your computer and use it in GitHub Desktop.
getsimple heirarchy test set
<?php
/**
* Generate random pagesArray with parent heirarchy
* 500 pages, 8 character slugs, 10% root level parents
*/
function getrandomstring($length) {
global $template;
settype($template, "string");
$template = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
/* this line can include numbers or not */
settype($length, "integer");
settype($rndstring, "string");
settype($a, "integer");
settype($b, "integer");
for ($a = 0; $a <= $length; $a++) {
$b = rand(0, strlen($template) - 1);
$rndstring .= $template[$b];
}
return $rndstring;
}
function getRandomPagesArray($pagecnt = 500, $sluglen = 8, $parentperc = 10){
$tmpArray = array();
for($i=0;$i<$pagecnt;$i++){
$randomword = getrandomstring($sluglen);
$tmpArray[$randomword] = array();
}
foreach($tmpArray as $key => &$ary){
$randomKey = array_rand($tmpArray);
$ary['url'] = $key;
$ary['parent'] = rand(0,100) < $parentperc ? '' : $randomKey ; // 10 % root level
}
return $tmpArray;
}
$pagesArray = getRandomPagesArray();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment