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

Prido's avatar
Level 2

Check conditions in Array

basically i have array like this

let arr = [
{
value_1: "1",
value_2: "1"
condition: "equal to",
conditionOperator:  "None"
},
{
value_1: "1",
value_2: "2"
conditon: "equal to",
conditionOperator:  "And"
},
{
value_1: "1",
value_2: "1"
condition: "not equal",
conditionOperator:  "And"
},
{
value_1: "1",
value_2: "1"
condition: "equal to",
conditionOperator:  "Or"
}
]

as you can see ts an array of conditions and need to check the condition for truthyness.. i would appreciate a function to handle this or clues ro the solution.

0 likes
2 replies
vincent15000's avatar

Please can you give an example of result you're waiting for ?

jaseofspades88's avatar

If you're validating an array, I suggest you look at this link: https://laravel.com/docs/9.x/validation#validating-arrays. This means you can validate your nested array.

Something like this based on the weak example you've provided...

$request->validate([
    'arr.*.value_1' => [
        'required',
        'numeric',
    ],
    'arr.*.value_2' => [
        'required',
        'numeric',
    ],
    'arr.*.condition' => [
        'required',
    ],
    'arr.*.conditionOperator' => [
        'required',
    ],
]);

Rather than simply expecting to copy and paste this and it instantly work, you might have to put other validation rules in each array.

1 like

Please or to participate in this conversation.