Ryan Ryan - 1 year ago 70
PHP Question

I need to ignore certain items of an array and create initials from remaining

I need to avoid the CN=Users, DC=aab, DC=local values that return from the array. Then save the INITIALS of the remaining names into a new array. Any help would be appreciated. I'm just not really sure where to start.
This is how it returns right now when I do the following.

$reportees = $_SESSION["user"]->directreports;
$reportees = implode(",", $reportees);

CN=John Doe,CN=Users,DC=aab,DC=local,CN=Jane Ann Doe,CN=Users,DC=aab,DC=local

Answer Source
$reportees = $_SESSION["user"]->directreports;
$blacklist = array('CN=Users', 'DC=aab', 'DC=local');

$arrayOfInitials = array();
foreach($reportees as $key=>$reportee){
    // ignore the unwanted values :
    if(!in_array($reportee, $blacklist)){
        // take only the value after the "=":
        $reportee = explode("=", $reportee);
            $reportee = $reportee[1];
            $reporteeNames = explode(" ", $reportee);
            $initials = "";
            // get the initials :
            foreach($reporteeNames as $name){
                $initials .= strtoupper($name[0]);
            $arrayOfInitials[] = $initials;


$initialsAsStr = implode(',', $arrayOfInitials);

The output will be :

string(10) "JD,B,JAD,B"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download