SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    array_diff understanding

    Hi there,

    I must be misunderstanding the functionality of array_diff... here are two var_dump's of two arrays I am looking to compare:

    Code:
    array(1) {
      [0]=>
      string(2) "41"
    }
    array(2) {
      [0]=>
      string(2) "41"
      [1]=>
      string(1) "9"
    }
    array_diff returns (whereby array(1) is the first argument and array(2) is the second argument in array_diff):

    Code:
    array(0) {
    }
    What? Why? Shouldn't the "9" entry be somewhere in the array_diff returned array?

    I've tried array_diff_assoc and array_diff_key and both return the same results.

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    array_diff() returns an array containing all the entries from the first array that are not present in any of the other arrays.
    Salathe
    Software Developer and PHP Manual Author.


Bookmarks

Posting Permissions

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