BASE . LOG, 'file_id' => $LOG_FILE_ID, // add file date 'print_file_date' => true, // set debug and print flags 'debug_all' => $DEBUG_ALL, 'echo_all' => $ECHO_ALL ?? false, 'print_all' => $PRINT_ALL, ]); // $_array = new CoreLibs\Combined\ArrayHandler(); // $array_class = 'CoreLibs\Combination\ArrayHandler'; $PAGE_NAME = 'TEST CLASS: ARRAY HANDLER'; print ""; print "" . $PAGE_NAME . ""; print ""; print '
Class Test Master
'; print '

' . $PAGE_NAME . '

'; // recursive array search $test_array = [ 'foo' => 'bar', 'input' => [ 'element_a' => [ 'type' => 'text' ], 'element_b' => [ 'type' => 'email' ], 'element_c' => [ 'type' => 'email' ], ], ]; echo "SOURCE ARRAY: " . DgS::printAr($test_array) . "
"; // frist return echo "ARRAYSEARCHRECURSIVE(email, [array], type): " . DgS::printAr(ArrayHandler::arraySearchRecursive('email', $test_array, 'type')) . "
"; echo "ARRAYSEARCHRECURSIVE(email, [array]['input'], type): " . DgS::printAr(ArrayHandler::arraySearchRecursive('email', $test_array['input'], 'type')) . "
"; // all return echo "ARRAYSEARCHRECURSIVEALL(email, [array], type): " . Dgs::printAr((array)ArrayHandler::arraySearchRecursiveAll('email', $test_array, 'type')) . "
"; echo "ARRAYSEARCHRECURSIVEALL(email, [array], type, false): " . Dgs::printAr((array)ArrayHandler::arraySearchRecursiveAll('email', $test_array, 'type', false)) . "
"; // simple search echo "ARRAYSEARCHSIMPLE([array], type, email): " . (string)ArrayHandler::arraySearchSimple($test_array, 'type', 'email') . "
"; $array_1 = [ 'foo' => 'bar' ]; $array_2 = [ 1, 2, 3 ]; $array_3 = [ 'alpha' => [ 'beta' => 4 ] ]; // recusrice merge print "ARRAYMERGERECURSIVE: " . DgS::printAr(SetVarType::setArray( ArrayHandler::arrayMergeRecursive($array_1, $array_2, $array_3) )) . "
"; // array difference $array_left = [ 'same' => 'data', 'left' => 'Has L' ]; $array_right = [ 'same' => 'data', 'right' => 'has R' ]; print "ARRAYDIFF: " . DgS::printAr(ArrayHandler::arrayDiff($array_left, $array_right)) . "
"; // in array check print "INARRAYANY([1,3], [array]): " . DgS::printAr(SetVarType::setArray( ArrayHandler::inArrayAny([1, 3], $array_2) )) . "
"; // flatten array print "FLATTENARRAY: " . DgS::printAr(ArrayHandler::flattenArray($test_array)) . "
"; print "FLATTENARRAYKEY: " . DgS::printAr(ArrayHandler::flattenArrayKey($test_array)) . "
"; // flatten for key set print "ARRAYFLATFORKEY: " . DgS::printAr(ArrayHandler::arrayFlatForKey($test_array, 'type')) . "
"; /** * attach key/value to an array so it becomes nested * * @param string $pre Attach to new (empty for new root node) * @param string $cur New node * @param array $node Previous created array * @return array Updated array */ function rec(string $pre, string $cur, array $node = []) { if (!is_array($node)) { $node = []; } print "
#### PRE: " . $pre . ", CUR: " . $cur . ", N-c: " . count($node) . " [" . join('|', array_keys($node)) . "]
"; if (!$pre) { print "** NEW
"; $node[$cur] = []; } else { if (array_key_exists($pre, $node)) { print "+ KEY FOUND: " . $pre . ", add: " . $cur . "
"; $node[$pre][$cur] = []; } else { print "- NOT FOUND: loop
"; foreach ($node as $_pre => $_cur) { print "> TRY: " . $_pre . " => " . count($_cur) . " [" . join('|', array_keys($_cur)) . "]
"; if (count($_cur) > 0) { $node[$_pre] = rec($pre, $cur, $_cur); } } } } return $node; } // $test = [ // 'A' => [ // 'B' => [], // 'C' => [ // 'D' => [], // 'E' => [ // 'F' => [] // ] // ] // ], // '1' => [], // '2' => [], // '3' => [ // 'G' => [] // ] // ]; // build a tested array for flatten $test = []; // core $test = rec('', 'A', $test); $test = rec('', '1', $test); $test = rec('', '2', $test); $test = rec('', '3', $test); $test = rec('3', 'G', $test); $test = rec('A', 'B', $test); $test = rec('A', 'C', $test); $test = rec('C', 'D', $test); $test = rec('C', 'E', $test); $test = rec('E', 'F', $test); // new $test = rec('C', 'U', $test); $test = rec('F', 'U', $test); $test = rec('', 'Al', $test); $test = rec('B', 'B1', $test); print "ORIGINAL: " . \CoreLibs\Debug\Support::printAr($test) . "
"; print "FLATTEN-c: " . \CoreLibs\Debug\Support::printAr(ArrayHandler::flattenArrayKey($test)) . "
"; $test = [ 'a' => ['a1' => 'a1foo', 'a2' => 'a1bar'], 1 => 'bar', 'c' => [2, 3, 4], 'd' => [ 'e' => [ 'de1' => 'subfoo', 'de2' => 'subbar', 'a2' => 'a1bar' ] ] ]; print "ORIGINAL: " . \CoreLibs\Debug\Support::printAr($test) . "
"; print "FLATTEN: " . \CoreLibs\Debug\Support::printAr(ArrayHandler::flattenArrayKey($test)) . "
"; // genAssocArray $db_array = [ 0 => ['a' => 'a1', 'b' => 2], 1 => ['a' => 'a2', 'b' => 3], 2 => ['a' => '', 'b' => ''], ]; // $key = false; $key = 'a'; // $value = false; $value = 'b'; $flag = false; $output = \CoreLibs\Combined\ArrayHandler::genAssocArray($db_array, $key, $value, $flag); print "OUTPUT: " . \CoreLibs\Debug\Support::printAr($output) . "
"; // error message print $log->printErrorMsg(); print ""; // __END__