Jump to content

variables


bagnallc

Recommended Posts

hi

i have a page with a form on, which has several variables associated with it.

when the submit button is clicked it takes you to another page which uses the set variables.

i am using isset to establish whether they are set or not.

i was wondering though, if there is a function which lists all variables that are set?

thanks
Link to comment
https://forums.phpfreaks.com/topic/15803-variables/
Share on other sites

ok many thanks for all replys. not sure whats best for my own purpose here.

in this particular instance, i want to set a new variable if any one of a number of variables from the previous page are set. some variables from the previous page have no bearing though.

so my current code would be

if(isset($a)) { $new="blah blah"; }
elseif(isset($b)) $new=blah blah"; }
elseif(isset($c)) $new=blah blah"; }
elseif(isset($d)) $new=blah blah"; }

im sure there must be a better way though?

i had thought there may be something along the lines of -

if(isset($a) or isset($b) or isset($c) or isset($d)) { $new="blah blah"; }

any ideas?


Link to comment
https://forums.phpfreaks.com/topic/15803-variables/#findComment-64654
Share on other sites

easiest way when coming off a $_POST like that is to extract() all your variables then test them like you and thorpe have already said:
[code]
<?php
extract($_POST);
if (isset($a) || isset($b) || isset($c) || isset($d)) $new = "blah blah";
?>
[/code]

notice that extract() will create variables from an array named by the key
Link to comment
https://forums.phpfreaks.com/topic/15803-variables/#findComment-64666
Share on other sites

a better option might be to name the POSTed fields with a unique prefix, e.g. eee_varname1, eee_varname2, etc.

then use the follwing code:
[code]
$flag=false;
foreach($_POST as $key=>$value)
{
    if(substr($key, 0, 4)='eee_')
    {
          $flag=true;
    }
}
if($flag)
{
    $new='blah, blah, blah...';
}
[/code]
Link to comment
https://forums.phpfreaks.com/topic/15803-variables/#findComment-64704
Share on other sites

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.