Arrays values not identical (but they are?)

前端 未结 3 2617
鱼传尺愫
鱼传尺愫 2021-02-20 17:47

I have two arrays. They seem to contain at least one identical set of values, but performing array_diff() does not return anything even though I think it should!

3条回答
  •  猫巷女王i
    2021-02-20 18:10

    After converting both strings to hex-escaped form using

    var_dump(preg_replace_callback('#.#', function($m) {
      return '\\x' . dechex(ord($m[0]));
    }, $input))
    

    , the result strings appear like this: http://jsfiddle.net/mgaWn/

    Looking at them in that form shows that the first string contains 5,·6·+·Extras, the second one contains 5,·6··+·Extras - there's a double space before the + sign.

    HTML collapses whitespace and this difference becomes completely invisible. It is generally a good idea to compare the data as close to its original format as possible, before any output format specifics (such as character encodings or this HTML whitespace minimization) get in your way.

提交回复
热议问题