Jump to content

[SOLVED] assigning two variables based on a third...


aolong

Recommended Posts

Is it valid to assign two variables based on the value of a third which is set from the originating form...

 

if ($property == "elfaroma_3000") {

$friendlyName = "Name1";

$propertyIP = "xxx.xxx.xxx.196";

}

elseif ($property == "buttconctr_3000") {

$friendlyName = "Name2";

$propertyIP = "xxx.xxx.xxx.135";

      } ...

 

my $friendlyName is being set, but the $propertyIP remains empty for some reason.

 

Thank you.

 

I see no problems with that code. Maybe you have made a typo along the way which is clearing the value of your $propertyIP variable.

 

I assume you have a rather long if/elseif statement here. You may be better of listing your properties within an array like so

$propertyList = array( 'elfaroma_3000'   => array( 'name' => 'Name 1',
                                                   'ip'   => 'xxx.xxx.xxx.196'
                                                  ),

                       'buttconctr_3000' => array( 'name' => 'Name 2',
                                                   'ip'   => 'xxx.xxx.xxx.135'
                                                  ),

                       /// etc
                     );

 

Now to retrieve the info on the property stored in $property you'd use

if(array_key_exists($propertyList, $property))
{
    $propertyInfo = $propertyList[$property];

    echo '<pre>'.print_r($propertyInfo, true);
}

I have checked and double checked my code and can find no error, but $propertyIP is still empty. Here's the kicker: I run the same code on a windows xampp install and it returns a value as expected. I copy the same file (UTF-8 unix breaks) and it returns nothing. What can be going on here?

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.