Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Comparing 2 Arrays

    Looking for a function if one exists that can compare 2 arrays and tell me the elements that are the same in each.

    My array example is:
    Code:
    Array
    (
        [0] => Array
            (
                [word] => the
                [nav] => Array
                    (
                        [0] => 1
                        [1] => 3
                        [2] => 7
                    )
    
                [sub] => Array
                    (
                        [0] => 1
                        [1] => 2
                    )
    
            )
    
        [1] => Array
            (
                [word] => char
                [nav] => Array
                    (
                        [0] => 1
                        [1] => 3
                    )
    
            )
    
        [nav] => Array
            (
                [0] => 1
                [1] => 3
                [2] => 7
            )
    
    )
    I am looking for similar numbers in the sub array ['nav'] and in the case above the results should be 1 and 3.

    Can anyone help?

    D.
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com

  • #2
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post
    Try having a look at:
    array-intersect
    Mike

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Thanks I will do.

    D.
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com

  • #4
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Another problem has occurred.

    I now have the following array:
    Code:
    Array
    (
        [0] => 0
        [1] => 1
        [2] => 2
    )
    where the values are indexes in another array.
    Since there are 3 values I was planning on adding these to the array_intersect function but I want to add them dynamically to the following:

    PHP Code:
    $aTmp array_intersect([array key values in here]); 
    Is this possible?

    Thanks for any help.
    D.
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •