aolong Posted June 4, 2009 Share Posted June 4, 2009 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 https://forums.phpfreaks.com/topic/160952-solved-assigning-two-variables-based-on-a-third/ Share on other sites More sharing options...
gijew Posted June 4, 2009 Share Posted June 4, 2009 Do you have an else clause in there to catch it if $property isn't found? Maybe nothing is coming back as true so the variable isn't being set. Link to comment https://forums.phpfreaks.com/topic/160952-solved-assigning-two-variables-based-on-a-third/#findComment-849403 Share on other sites More sharing options...
wildteen88 Posted June 4, 2009 Share Posted June 4, 2009 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 https://forums.phpfreaks.com/topic/160952-solved-assigning-two-variables-based-on-a-third/#findComment-849406 Share on other sites More sharing options...
aolong Posted June 4, 2009 Author Share Posted June 4, 2009 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 https://forums.phpfreaks.com/topic/160952-solved-assigning-two-variables-based-on-a-third/#findComment-849505 Share on other sites More sharing options...
aolong Posted June 5, 2009 Author Share Posted June 5, 2009 I wish I could say I found the problem, but this morning it just worked... Link to comment https://forums.phpfreaks.com/topic/160952-solved-assigning-two-variables-based-on-a-third/#findComment-849955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.