Create a custom rule and check any array with the desired constraints. https://codeigniter4.github.io/userguide/libraries/validation.html#creating-a-rule-class
Sample class:
class IdRules
{
/**
* Use as 'required|valid_ids[100,intval,string]'
*/
public function valid_ids($value = null, string $params, array $data = [], ?string $error = null): bool
{
$rules = explode(',', $params);
if (! is_array($value)) {
$error = 'Not array';
return false;
}
if (count($value) > $rules[0]) {
$error = 'The array is too large';
return false;
}
foreach ($value as $k => $v) {
// validation `ids` and return `bool`
if (gettype($k) === $rules[1]) {}
if (gettype($v) === $rules[2]) {}
}
return true;
}
}