diff --git a/www/admin/class_test.array.php b/www/admin/class_test.array.php index 9424889b..38f39220 100644 --- a/www/admin/class_test.array.php +++ b/www/admin/class_test.array.php @@ -342,38 +342,6 @@ print "(ksort): " . DgS::printAr(ArrayHandler::ksortArray($nested)) . "
"; print "
"; -$search_array = [ - 'table_lookup' => [ - 'match' => [ - ['param' => 'access_d_cd', 'data' => 'a_cd', 'time_validation' => 'on_load',], - ['param' => 'other_block', 'data' => 'b_cd'], - ['pflaume' => 'other_block', 'data' => 'c_cd'], - ['param' => 'third_block', 'data' => 'd_cd', 'time_validation' => 'cool'], - ['special' => 'other_block', 'data' => 'e_cd', 'time_validation' => 'other'], - ] - ] -]; -print "Search: " . DgS::printAr($search_array) . "
"; -print "Result (all): " . Dgs::printAr(ArrayHandler::findArraysMissingKey( - $search_array, - 'other_block', - 'time_validation' -)) . "
"; -print "Result (key): " . Dgs::printAr(ArrayHandler::findArraysMissingKey( - $search_array, - 'other_block', - 'time_validation', - 'pflaume' -)) . "
"; -print "Result (key): " . Dgs::printAr(ArrayHandler::findArraysMissingKey( - $search_array, - 'other_block', - ['data', 'time_validation'], - 'pflaume' -)) . "
"; - -print "
"; - $search_array = [ 'a' => [ 'lookup' => 1, @@ -528,6 +496,45 @@ $result = ArrayHandler::selectArrayFromOption( ); print "*2*Result: " . DgS::printAr($result) . "
"; +print "
"; + +$search_array = [ + 'table_lookup' => [ + 'match' => [ + ['param' => 'access_d_cd', 'data' => 'a_cd', 'time_validation' => 'on_load',], + ['param' => 'other_block', 'data' => 'b_cd'], + ['pflaume' => 'other_block', 'data' => 'c_cd'], + ['param' => 'third_block', 'data' => 'd_cd', 'time_validation' => 'cool'], + ['special' => 'other_block', 'data' => 'e_cd', 'time_validation' => 'other'], + ] + ] +]; +print "Search: " . DgS::printAr($search_array) . "
"; +print "Result (all, search single): " . DgS::printAr(ArrayHandler::findArraysMissingKey( + $search_array, + 'other_block', + 'time_validation' +)) . "
"; +print "Result (key limit): " . DgS::printAr(ArrayHandler::findArraysMissingKey( + $search_array, + 'other_block', + 'time_validation', + 'pflaume' +)) . "
"; +print "Result (all, search array): " . DgS::printAr(ArrayHandler::findArraysMissingKey( + $search_array, + 'other_block', + ['data', 'time_validation'], +)) . "
"; +print "Result (key limit, search array): " . DgS::printAr(ArrayHandler::findArraysMissingKey( + $search_array, + 'other_block', + ['data', 'time_validation'], + 'pflaume' +)) . "
"; + +print "
"; + print ""; // __END__ diff --git a/www/lib/CoreLibs/Combined/ArrayHandler.php b/www/lib/CoreLibs/Combined/ArrayHandler.php index eef5129f..53a8bc20 100644 --- a/www/lib/CoreLibs/Combined/ArrayHandler.php +++ b/www/lib/CoreLibs/Combined/ArrayHandler.php @@ -248,12 +248,15 @@ class ArrayHandler * If not found return an array with the array block there the required key is missing, * the path as string with seperator block set and the missing key entry * - * @param array $in_array - * @param string|int|float|bool $search_value - * @param string|array $required_key - * @param ?string $search_key [null] - * @param string $path_separator [DATA_SEPARATOR] - * @param string $current_path + * alternate to findArraysWithMissingKey (single missing key) + * + * @param array $in_array Array to search in + * @param string|int|float|bool $search_value Value that must be set in any + * (or with search_key in one entry of the array) + * @param string|array $required_key Key or Keys that must be set + * @param ?string $search_key [null] limit search_value check to this key + * @param string $path_separator [DATA_SEPARATOR] For the path string separator + * @param string $current_path [''] Current path in the array (used for recursion) * @return array,path?:string,missing_key?:array}> */ public static function findArraysMissingKey( @@ -272,14 +275,14 @@ class ArrayHandler // Check if this array contains the search value // either any value match or with key if ($search_key === null) { - $containsValue = in_array($search_value, $value, true); + $contains_value = in_array($search_value, $value, true); } else { - $containsValue = array_key_exists($search_key, $value) && $value[$search_key] === $search_value; + $contains_value = array_key_exists($search_key, $value) && $value[$search_key] === $search_value; } // If it contains the value but doesn't have the required key if ( - $containsValue && + $contains_value && ( ( is_string($required_key) &&