0

How can I validate the multidimensional array.My array is like

Array
(
    [level] => Array
        (
            [1] => 1
            [2] => 2
        )

    [subject] => Array
        (
            [1] => Array
                (
                    [0] => 4
                    [1] => 9
                )

            [2] => Array
                (
                    [0] => 4
                )

        )

)

I want to check the keys for [level] is in [subject]. Please help me. How it is possible.

2 Answers 2

1

If I understood:

array_diff_key($myArray['level']), $myArray['subject']);

sample: http://codepad.org/i00KNhDJ

Order is important:

array_diff_key($myArray['level']), $myArray['subject']) !== array_diff_key($myArray['subject']), $myArray['level']);
Sign up to request clarification or add additional context in comments.

1 Comment

Use array_diff_key?
0
if (count(array_intersect_key($array['level'], $array['subject'])) !=
    count($array['level'])) {
    echo 'level and subject have different keys';
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.