@ 2013-08-02T13:07:40Z <?php
error_reporting(E_ALL);
function getCollectionParentIDFromChildID($cID) {
if(is_numeric($cID)) {
if($cID > 1) {
return '1';
}
if($cID == 1) {
return '0';
}
}
return null;
}
function populateParentIDArray_current($cID) {
global $cParentIDArray;
$cParentID = getCollectionParentIDFromChildID($cID);
if($cParentID > -1) {
if(!in_array($cParentID, $cParentIDArray)) {
$cParentIDArray[] = $cParentID;
}
populateParentIDArray_current($cParentID);
}
}
function populateParentIDArray_new($cID) {
global $cParentIDArray;
$cParentID = getCollectionParentIDFromChildID($cID);
if(is_numeric($cParentID)) {
if(!in_array($cParentID, $cParentIDArray)) {
$cParentIDArray[] = $cParentID;
}
if($cParentID > 0) {
populateParentIDArray_new($cParentID);
}
}
}
function runTest($cID) {
global $cParentIDArray;
echo "Test case for "; var_dump($cID);
$cParentIDArray = array();
populateParentIDArray_current($cID);
ob_start();
var_dump($cParentIDArray);
$current = ob_get_contents();
ob_end_clean();
$cParentIDArray = array();
populateParentIDArray_new($cID);
ob_start();
var_dump($cParentIDArray);
$new = ob_get_contents();
ob_end_clean();
if($current === $new) {
echo "Passed: ", $current;
}
else {
echo "###ERROR\nCURRENT: ", $current, "\nNEW: ", $new, "\n";
}
}
runTest('3');
runTest('1');
runTest('0');
runTest(3);
runTest(1);
runTest(0);
runTest(null);
runTest('');
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 4.3.0 - 4.3.11 , 4.4.0 - 4.4.9 , 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.38 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Test case for string(1) "3"
Passed: array(2) {
[0]=>
string(1) "1"
[1]=>
string(1) "0"
}
Test case for string(1) "1"
Passed: array(1) {
[0]=>
string(1) "0"
}
Test case for string(1) "0"
Passed: array(0) {
}
Test case for int(3)
Passed: array(2) {
[0]=>
string(1) "1"
[1]=>
string(1) "0"
}
Test case for int(1)
Passed: array(1) {
[0]=>
string(1) "0"
}
Test case for int(0)
Passed: array(0) {
}
Test case for NULL
Passed: array(0) {
}
Test case for string(0) ""
Passed: array(0) {
}
preferences:dark mode live preview
300.41 ms | 407 KiB | 452 Q