Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

value comparision

Status
Not open for further replies.

Netwrkengeer

IS-IT--Management
Apr 4, 2001
184
US
How would I compare a value and then have the value replaced if it was true.
for example
I have variables A,1,2
"A" is the variable I want to reference at the end
"1" and "2" are the variables that I want to compare to "A"
{1 and 2} have to be in an array because I want to add more variable to compare to "A" automatically.
A=47
1=43
2=51

A<=1 A remains 47
A<=2 A becomes 51
 
first of all, you can have variables with names that start with numbers. so 1 and 2 are illegal variable names.

let's say you want to compare $value_to_compare with an array called $values:

Code:
foreach ($values as $value) {
   if ($value_to_compare == $value) {
      do what you want here....
   }
}

if all you want is to compare two variables do this:

Code:
$value1 = 2;
$value2 = 3;
$value_to_compare = 2;

$value_to_compare = $value_to_compare == $value1 ? $value1 : $value2;

what this does is this: in the case that $value_to_compare equals $value1 make $value_to_compare as $value1, otherwise make $value_to_compare as $value2.


hope this helps


:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top