-1

I have toe different multidimensional array following :

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

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

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

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

    [3] => Array
        (
            [0] => 1
        )

)

I want to check small multidimensional array exists in bigger array. Any suggestion please. I am using

$diff = Hash::diff(samllarray, $bigger array); 

of cakephp and its result is

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

    [3] => Array
        (
            [0] => 1
        )

)

but in result I want only 3rd key but its also given me 2rd key see above

8
  • Have you tried something? Commented Apr 17, 2015 at 6:57
  • @Andrew How should you be able to tell with count() if a subArray exists in another array?! Commented Apr 17, 2015 at 6:59
  • what is the expected result for your example? Commented Apr 17, 2015 at 7:01
  • @Rizier123 Oh, I misunderstood the question. I though OP wanted to check if an array is multidimensional. Commented Apr 17, 2015 at 7:02
  • @Andrew If then you can't tell with count() if it is multidimensional. Commented Apr 17, 2015 at 7:04

1 Answer 1

0

You can use is_array() to see if a variable is an array.

$arrs = array(
    0 => "big array",
    1 => "big array",
    3 => array(
        0 => "nested array",
        1 => "nested array"
    )
);

foreach ($arrs as $key=>$value) {
    if (is_array($value)) {
        echo "we've got an array at index {$key}";
    }
}

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.