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.

 

Link to comment
Share on other sites

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);
}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.