In response to the first message ldap_get_entries, I think there is some confusion with the dynamic typing of php.
If the result is a string doing $foo[0] will return the first character of the string.
In the case of an array $foo[0] will return the entire first element.
Its not to do with the 'dn' in particular, rather the fact that the dn is a scalar value (ie a string) rather than an array, and the indexing works differently in either case.
For debugging purposes I would recommend using something like :
$value = is_array($foo) ? $foo[0] : $foo;
or
$value = is_array($foo) ? implode($foo, $delimiter) : $foo;