0

I am trying to use a php inbuilt function to compare 2 arrays.

$json = json_decode(file_get_contents("new.json"), true);
$last_json = json_decode(file_get_contents("last.json"), true);
$difference = array_diff_assoc($json, $last_json);

Notice: Array to string conversion in /storage/whitelist_update.php on line 10

Any help would be appreciated!

Barmar
  • 741,623
  • 53
  • 500
  • 612
Martin O
  • 51
  • 1
  • 7
  • 2
    Can you post a couple more lines around line 10, your issue isn't here... since you're not converting an array to a string. – ʰᵈˑ May 06 '16 at 16:16
  • Line 10 is the $difference = array_diff_assoc() function. – Martin O May 06 '16 at 16:17
  • 1
    btw: you most likely meant `conversion`, not `conversation` I assume.. – Marcin Orlowski May 06 '16 at 16:18
  • https://gyazo.com/bef683da4db1afa49ec17bfbf28f09d7 – Martin O May 06 '16 at 16:18
  • 1
    The issue is *NOT* on your `array_diff_assoc` line! Look at your code again, there is a `require_once` line. What does is, basically copy & paste that file into the current line. So line 10 is *actually* a line inside the included file. – gen_Eric May 06 '16 at 16:23
  • 1
    @RocketHazmat No. Luckily this is not the php behavior. – fusion3k May 06 '16 at 16:31
  • @Rizier123 in what sense is this question a duplicate of the one you linked (or did not specify, I don't quite understand)? – Walter Tross May 06 '16 at 16:39
  • @fusion3k: Am I wrong in my comment? – gen_Eric May 06 '16 at 16:41
  • 1
    "Array to string conversion" means somewhere, you are using a variable in a ***string*** context, but that variable is actually an array. For example: `$a = []; echo $a;` The variable is "converted" to a string, but actually all you get is the string `"Array"`. See: https://eval.in/566676 – gen_Eric May 06 '16 at 16:43
  • @RocketHazmat Yup. If the error is in included/required file, its path is in the error notice. – fusion3k May 06 '16 at 16:46
  • @fusion3k: I tested this and... turns our you're right! I still think the error is in that file though since "Array to string conversion" makes no sense for `array_diff_assoc`. – gen_Eric May 06 '16 at 16:48
  • 3
    It seems that the answer is here: http://stackoverflow.com/questions/18253885/array-to-string-conversion-and-only-variables-should-be-passed-by-reference – Walter Tross May 06 '16 at 16:51
  • @WalterTross: That looks like it would explain it! Good job. You should post that as an answer (or close as a dupe). – gen_Eric May 06 '16 at 16:52
  • 1
    @RocketHazmat I have already invested too much time... Go ahead if you want – Walter Tross May 06 '16 at 16:54
  • 1
    @RocketHazmat This error would happen if the array is 2-dimensional. – Barmar May 06 '16 at 17:00
  • 1
    Thanks for all the replies! The issue was that the file couldn't read "last.json" but when I changed that to its entire link it seems to work. Thanks guys! :D – Martin O May 06 '16 at 17:00

0 Answers0