findArraysMissingKey: php param documentation update
This commit is contained in:
@@ -342,38 +342,6 @@ print "(ksort): " . DgS::printAr(ArrayHandler::ksortArray($nested)) . "<br>";
|
|||||||
|
|
||||||
print "<hr>";
|
print "<hr>";
|
||||||
|
|
||||||
$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) . "<br>";
|
|
||||||
print "Result (all): " . Dgs::printAr(ArrayHandler::findArraysMissingKey(
|
|
||||||
$search_array,
|
|
||||||
'other_block',
|
|
||||||
'time_validation'
|
|
||||||
)) . "<br>";
|
|
||||||
print "Result (key): " . Dgs::printAr(ArrayHandler::findArraysMissingKey(
|
|
||||||
$search_array,
|
|
||||||
'other_block',
|
|
||||||
'time_validation',
|
|
||||||
'pflaume'
|
|
||||||
)) . "<br>";
|
|
||||||
print "Result (key): " . Dgs::printAr(ArrayHandler::findArraysMissingKey(
|
|
||||||
$search_array,
|
|
||||||
'other_block',
|
|
||||||
['data', 'time_validation'],
|
|
||||||
'pflaume'
|
|
||||||
)) . "<br>";
|
|
||||||
|
|
||||||
print "<hr>";
|
|
||||||
|
|
||||||
$search_array = [
|
$search_array = [
|
||||||
'a' => [
|
'a' => [
|
||||||
'lookup' => 1,
|
'lookup' => 1,
|
||||||
@@ -528,6 +496,45 @@ $result = ArrayHandler::selectArrayFromOption(
|
|||||||
);
|
);
|
||||||
print "*2*Result: " . DgS::printAr($result) . "<br>";
|
print "*2*Result: " . DgS::printAr($result) . "<br>";
|
||||||
|
|
||||||
|
print "<hr>";
|
||||||
|
|
||||||
|
$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) . "<br>";
|
||||||
|
print "Result (all, search single): " . DgS::printAr(ArrayHandler::findArraysMissingKey(
|
||||||
|
$search_array,
|
||||||
|
'other_block',
|
||||||
|
'time_validation'
|
||||||
|
)) . "<br>";
|
||||||
|
print "Result (key limit): " . DgS::printAr(ArrayHandler::findArraysMissingKey(
|
||||||
|
$search_array,
|
||||||
|
'other_block',
|
||||||
|
'time_validation',
|
||||||
|
'pflaume'
|
||||||
|
)) . "<br>";
|
||||||
|
print "Result (all, search array): " . DgS::printAr(ArrayHandler::findArraysMissingKey(
|
||||||
|
$search_array,
|
||||||
|
'other_block',
|
||||||
|
['data', 'time_validation'],
|
||||||
|
)) . "<br>";
|
||||||
|
print "Result (key limit, search array): " . DgS::printAr(ArrayHandler::findArraysMissingKey(
|
||||||
|
$search_array,
|
||||||
|
'other_block',
|
||||||
|
['data', 'time_validation'],
|
||||||
|
'pflaume'
|
||||||
|
)) . "<br>";
|
||||||
|
|
||||||
|
print "<hr>";
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -248,12 +248,15 @@ class ArrayHandler
|
|||||||
* If not found return an array with the array block there the required key is missing,
|
* 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
|
* the path as string with seperator block set and the missing key entry
|
||||||
*
|
*
|
||||||
* @param array<mixed> $in_array
|
* alternate to findArraysWithMissingKey (single missing key)
|
||||||
* @param string|int|float|bool $search_value
|
*
|
||||||
* @param string|array<string> $required_key
|
* @param array<mixed> $in_array Array to search in
|
||||||
* @param ?string $search_key [null]
|
* @param string|int|float|bool $search_value Value that must be set in any
|
||||||
* @param string $path_separator [DATA_SEPARATOR]
|
* (or with search_key in one entry of the array)
|
||||||
* @param string $current_path
|
* @param string|array<string> $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<array{content?:array<mixed>,path?:string,missing_key?:array<string>}>
|
* @return array<array{content?:array<mixed>,path?:string,missing_key?:array<string>}>
|
||||||
*/
|
*/
|
||||||
public static function findArraysMissingKey(
|
public static function findArraysMissingKey(
|
||||||
@@ -272,14 +275,14 @@ class ArrayHandler
|
|||||||
// Check if this array contains the search value
|
// Check if this array contains the search value
|
||||||
// either any value match or with key
|
// either any value match or with key
|
||||||
if ($search_key === null) {
|
if ($search_key === null) {
|
||||||
$containsValue = in_array($search_value, $value, true);
|
$contains_value = in_array($search_value, $value, true);
|
||||||
} else {
|
} 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 it contains the value but doesn't have the required key
|
||||||
if (
|
if (
|
||||||
$containsValue &&
|
$contains_value &&
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
is_string($required_key) &&
|
is_string($required_key) &&
|
||||||
|
|||||||
Reference in New Issue
Block a user