Q:

Using PHP with LDAP returns all results into one connected line

I'm trying to get user information from my Active Directory through LDAP. Im using for loops to retrieve each username for a specific AD OU. All results are showing in one line without any separation. If i put 
$LDAP_CN into array it just creates a lot of different arrays.
Here is my PHP code:
$entries = ldap_get_entries($ldap_connection, $result);

for ($x=0; $x<$entries['count']; $x++){

    $LDAP_CN = "";
    if (!empty($entries[$x]['cn'][0])) {
        $LDAP_CN = $entries[$x]['cn'][0];
        if ($LDAP_CN == "NULL"){
            $LDAP_CN = "";
        }
      }
    echo($LDAP_CN);
}

output:
Name LastnameName1 Lastname1Name2 Lastname2Name3 Lastname3Name4 Lastname4 ant etc.

When i try to var_dump $LDAP_CN it gives output like that:
string (13) "Name Lastname"
string (15) "Name1 Lastname1"
string (15) "Name2 Lastname2"
string (15) "Name3 Lastname3"
string (15) "Name4 Lastname4"
etc..

So i'm guessing that it knows how to separate them. But how ? I tried explode it just creates a lot of arrays.. Also if i put echo out of the loop it just returns last result.

A:

All results in one array:
$LDAP_CN = [];
for ($x=0; $x<$entries['count']; $x++){

    if (!empty($entries[$x]['cn'][0])) { 
        $LDAP_CN[] = $entries[$x]['cn'][0] == "NULL" ? "" : $entries[$x]['cn'][0];      
    }
}

print_r($LDAP_CN);

