-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

NorthCat
  • 9,643
  • 16
  • 47
  • 50
  • Have you tried something? – Rizier123 Apr 17 '15 at 06:57
  • @Andrew How should you be able to tell with `count()` if a subArray exists in another array?! – Rizier123 Apr 17 '15 at 06:59
  • what is the expected result for your example? – niyou Apr 17 '15 at 07:01
  • @Rizier123 Oh, I misunderstood the question. I though OP wanted to check if an array is multidimensional. – Andrei Apr 17 '15 at 07:02
  • @Andrew If then you can't tell with count() if it is multidimensional. – Rizier123 Apr 17 '15 at 07:04
  • @Rizier123 Of course you can. Count the array twice. Once using `count` without an argument and secondly using `count` with the `COUNT_RECURSIVE` argument. If they're equal, it's not multidimensioanl. If they're not, it is. For example `count($array) == count($array, COUNT_RECURSIVE)` – Andrei Apr 17 '15 at 07:07
  • if array keys value is array, its ok. Compare these values to see your answer. Are they the same or not. – animaacija Apr 17 '15 at 07:10
  • This has *nothing* to do with CakePHP. I really don't get it why so many people tag random php and js problems with *CakePHP*. I've updated the question with a better matching tag. – floriank Apr 17 '15 at 08:17

1 Answers1

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}";
    }
}
Al.G.
  • 4,327
  • 6
  • 31
  • 56
Tomasz Cz.
  • 315
  • 5
  • 22