Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jrdavidson's avatar

Validation Rule for an Array Key

I'm trying to figure out what I would do for a validation rule so that type2 cannot be in any of the groups of students. I know of the Rule::In but not sure how I can validate against a key.

'courses.*.students.*.*' => [Rule::in(['type2'])],

Can someone tell me what I'm doing wrong?

array:1 [
    "courses" => array:1 [
        1 => array:3 [
            "students" => array:2 [
                0 => array:2 [
                    "type1" => array:1 [
                       0 => 1
                    ]
                    "type2" => array:1 [
                        0 => 3
                    ]
                ]
                1 => array:1 [
                     "type1" => array:1 [
                          0 => 2
                     ]
                 ]
            ]
           "preview" => "This is an example couse preview."
        ]
    ]
]
0 likes
1 reply
jrdavidson's avatar

Is there anyone that has had to check keys of a post array?

Please or to participate in this conversation.