Jump to content

greater than or equal to variable


madmega

Recommended Posts

Hi, i am trying to write a part of script for google shopping export, and all i want is that in this line, everything that is 0 or smaller, the line "pre-order" krijgt and everything that is 1 or greater the line "in stock"

This is what i've got now, but it doesn't work

I removed the rest of the long code.

 

$patterns = array();
$patterns[0] = '=<0';
$patterns[1] = '=>1';
$replacements = array();
$replacements[0] = 'vooraf bestellen';
$replacements[1] = 'op voorraad';

         if(OPTIONS_TONEN_FEED_AVAILABILITY == 1)
            $output .= "~" . preg_replace($patterns, $replacements, $row->quantity);

Link to comment
https://forums.phpfreaks.com/topic/262288-greater-than-or-equal-to-variable/
Share on other sites

I'm pretty sure that preg_replace doesn't work like that. To use a comparison operator, you could do something like:

 

<?php
//...

if($row->quantity     <= 0) { $output .= "~vooraf bestellen"; }
elseif($row->quantity >= 1) { $output .= "~op voorraad"; }

?>

 

 

Will there ever be values between 0 and 1?

IT WORKED, your script did the trick...thank you !!!

 

Glad to hear. :D

 

Note that since it sounds like $row->quantity will never be between 0 and 1, you could skip the second test:

 

<?php
//...

if($row->quantity <= 0) { $output .= "~vooraf bestellen"; }
else                    { $output .= "~op voorraad"; }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.