I have searched through many many topics and none have helped me with my specific need as yet.
I tried many options from This Thread but none have been quite right.
I am making a config generator for switches and routers, I am trying to streamline it, so rather than have a config array for each interface, i'll have config array for each type of layout and have the interface name as a variable. I have the web page posting to the script and I have the page posting the port layout per post, with each interface as its own variable.
i.e.
$fa1 = "DESKTOP";
$fa2 = "VOIP";
$fa3 = "DESKTOP";
$fa4 = "";
$fa5 = "DESKTOP";
etc. I am trying to use a foreach loop to go through each interface (as such)
$ints = array($fa1,$fa2,$fa3,$fa4,etc);
foreach ($ints as $line) {
if ($line == "PC") {
file_put_contents($file, $pcarray.FILE_APPEND);
}
if ($line == "VOIP") {
file_put_contents($file,$voiparray.FILE_APPEND);
}
}
with the interface setup as an array:
$pcarray = array(
'interface ' .$interface,
'configetc'
);
I need a function to get the name of the variable for the interface so I can assign it to the $interface variable.
all the examples I've found and tried thus far dont seem compatible with like valued variables.
ie. for the above, most would return fa1 for everything that comes up DESKTOP rather than fa3 for the next desktop one.
an example of the ones that dont quite work how I want is:
function print_var_name($var) {
foreach($GLOBALS as $var_name => $value) {
if ($value === $var) {
return $var_name;
}
}
return false;
}
This one, for each variable value repetition after the first just returned the first variables name.
EDIT: What I am wanting to get back would be:
(as the written array)
interface fa1
standard desktop config
interface fa2
standard voip config
interface fa3
standard desktop config
interface fa5
standard desktop config
where as currently im getting:
interface fa1
standard desktop config
interface fa2
standard voip config
interface fa1
standard desktop config
interface fa1
standard desktop config