如何在sprintf中放置条件

I'm echoing the results of a query with this loop:

 $cds = toArray($result->GetClassDescriptionsResult->ClassDescriptions->ClassDescription);
 foreach ($cds as $cd) {
    $cdsHtml .= sprintf('<p><strong>%s</strong><br />%s<br />%s</p>', $cd->Name, $cd->Description, $cd->Prereq);
 }

 echo($cdsHtml);

This is displaying a list of classes. There is a parameter called $cd->ScheduleTypeand that can either be "DropIn" or "Enrollment". Currently it is displaying both types. I want to only display "DropIn".

I tried this:

 $cds = toArray($result->GetClassDescriptionsResult->ClassDescriptions->ClassDescription);
     foreach ($cds as $cd) {
// conditional
if ($cd->ScheduleType="DropIn"){

        $cdsHtml .= sprintf('<p><strong>%s</strong><br />%s<br />%s</p>', $cd->Name, $cd->Description, $cd->Prereq);
     }

}
echo($cdsHtml);

But that did not filter out the other kind and also gave me lots of duplicates of all the classes for some reason...Any help would be appreciated!

if ($cd->ScheduleType = "DropIn") {

should be entered as:

if ($cd->ScheduleType == "DropIn") {

The valid comparison operators are found here, and = is nowhere to be found.

What you're doing is assignment, which basically sets $cd->ScheduleType to "DropIn", then uses that value as the if condition. Since that value is truthy (see "Converting to boolean" here), it always executes the if body.