在php中使用if()来查看数组中的日期是否等于存储在变量中的日期

I have the following code in my index.php:

$d1 = date('Y-m-d', strtotime("-4 days"));
$newrecord = [];
  for($i = 1; $i <= sizeof($methods); $i++) {
      $keys = ["Email", "FirstName", "LastName"];
      $newrecord[$i][0] = $methods[$i][1];
      $newrecord[$i][1] = $methods[$i][2];
      $newrecord[$i][2] = $methods[$i][3];
      $newrecord[$i][3] = explode(" ", $methods[$i][6]);
      $newrecord[$i][3] = $newrecord[$i][3][0];

      $newrecord[$i][4] = $d1;
      if ($newrecord[$i][3] == $newrecord[$i][4]){
        $newrecord[$i][5] = "New Entry";
      }
}

I am expecting to loop through my entire $methods array, and after assigning new values to each of my $newrecord[$i] entries, I need to check whether the value of $newrecord[$i][3] equals the date of 4 days ago.

The problem is that it doesn't look like the if() check is successful, because none of my arrays contain the [5] => "New Entry" array component.

However, I know that there are 120 instances in the array when these do equal each other. For instance:

[23] => Array ( [3] => 2018-07-15 [4] => 2018-07-15 [Email] => me@example.com [FirstName] => John [LastName] => Doe )

Returns for record [23] when I print the output of all the arrays, and there are 120 of them that are like this in total (out of around 8000).

This same thing happens when i just put if($newrecord[$i][3] == $d1) in the if statement.

Any advice on what I'm missing? I appreciate the help.

Note: the values for ["Email"] ["FirstName"] ["LastName"] occur later in the function, this is just a snippet of it to keep it more concise.

The reason the if() statement isn't working is because the true value of the date within the array was not the same as was returned with the $d1 variable.

This was discovered when I clicked "view page source" on my Chrome browser and inspected the arrays being returned by the var_dump call. Specifically, there were spaces between the characters (i.e. 2018-07-15 became 2 0 1 8 - 0 5 - 0 6).

Further investigation revealed little black diamonds with "?" inside them in the CSV file so I'm assuming the character code was wrong when importing these.

The solution, after much trial and error, was to use preg_replace() in the following format:

$newrecord[$i][3] = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $newrecord[$i][3]);

Where /[\x00-\x1F\x7F-\xFF]/ is the search for unwanted characters, I took from this question

When ran, the if() statement executed just fine.