The following example toggles the label of the Roads layer between Roads and Streets.
MgInitializeWebTier ($webconfigFilePath);
$userInfo = new MgUserInformation($mgSessionId);
$siteConnection = new MgSiteConnection();
$siteConnection->Open($userInfo);
$resourceService =
$siteConnection->CreateService(MgServiceType::ResourceService);
$map = new MgMap();
$map->Open($resourceService, $mgMapName);
$layers = $map->GetLayers();
$roadLayer = $layers->GetItem('Roads');
$roadLabel = $roadLayer->GetLegendLabel();
if ($roadLabel == 'Roads')
$newLabel = 'Streets';
else
$newLabel = 'Roads';
$roadLayer->SetLegendLabel($newLabel);
// You must save the updated map or the
// changes will not be applied
// Also be sure to refresh the map on page load.
$map->Save($resourceService);