Q:

White space at start of encoded json array

Admittedly it has been a while since I have been in the php world, but i'm not sure why I am getting 3 spaces at the start of my json_encode string.
"   [{"id":"1","display_name":"Bob"}]"

This is the php i have:
$stmt = $conn->prepare("SELECT * FROM users");

$queryResult = array();
if ($stmt->execute()) {
  while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
      $queryResult[] = $row;
  }
  echo json_encode($queryResult);
}

When I echo print_r($stmt->fetch(PDO::FETCH_ASSOC))﻿ I get the following:
   Array
(
    [id] => 1
    [display_name] => Twitch Dock John
)

The 3 spaces are there as well.. what have I done wrong (expecting an incoming face-palm moment)?

A:

You can possibly figure the spot in your codebase where output starts by determining where HTTP headers have been sent:
if (headers_sent($file, $line)) {
    echo "Ouput starts on: $file: $line\n";
}

