I have a recordset object and I pass that to a function. I also want to pass a property to the function, along with a value to test this against.
Within the function I loop through the recordset and if the test value == the object's property value on this iteration then I want to do something but I can't figure out how to pass in some kind of reference to the property I want to test against and the work around I have is plain clunky.
Here is what I have:
Code: Select all
function getNavListItems($rsRecordset, $iFieldToTest, $iValueToTest)
{
// Ya di ya...
foreach ( $rsRecordset as $record )
{
$bTestResult = false;
switch ($iFieldToTest)
{
case 0:
if ( $record->pageId == $iValueToTest )
{
$bTestResult = true;
}
break;
case 1:
if ( $record->parentPageId == $iValueToTest )
{
$bTestResult = true;
}
break;
}
if ( $bTestResult )
{
// Do stuff
}
else
{
// Do other stuff
}
}
return $sStuff;
}Code: Select all
function getNavListItems($rsRecordset, $propertyToTest, $iValueToTest)
{
// Ya di ya...
foreach ( $rsRecordset as $record )
{
if ( $record->$propertyToTest == $iValueToTest )
{
// Do stuff
}
else
{
// Do other stuff
}
}
return $sStuff
}