Code Help


#1

Hi Guys, Im a beginner with PHP. And I’m trying to do the following. Everytime the value ‘Junior’ for ‘gender’ is picked up I want Junior to change to Male. I was trying to use the If Else statement but became unstuck. Can anyone help please?

$product_data[‘gender’] = $product->getAttributeText(‘gender’);


#2

How about:

[php]if($product_data[‘gender’] == ‘Junior’){ $product_data[‘gender’] =‘Male’;}[/php]

or

[php]$product_data[‘gender’] = str_replace(‘Junior’,‘Male’,$product_data[‘gender’]);[/php]


#3

If you have more ‘gender’ values you want mapped to other values this may work.
( I’m only aware of the genders ‘Male’, ‘Female’ and then there are some Hermaphrodites, but they’re usually not human ;D )

[php]
$genderMap = array(
/* In-gender out-gender /
‘Male’ => ‘Male’,
‘Female’ => ‘Female’,
‘Junior’ => ‘Male’,
‘Fem’ => ‘Female’,
/
&c. */
);

echo $genderMap[$product_data[‘gender’]];
[/php]

Hope it helps, good luck!


#4

Just thought I’d register to say thankyou guys! didnt expect such useful replies! Code works perfectly for the googlefeed we’re using!

Chris