form variable thingy :S

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

form variable thingy :S

Post by John Cartwright »

k I have this array... but this is only a few of them

Code: Select all

<?php
$formvariables = array('$type','$type_other','$logodesign','$bannerdesign','$graphicdesign','$shoppingcart',
					   '$interactivefeatures','$flashanimationandpresentation','$webhosting','$domainnameregistration','$sitemaintenance',
					   '$editingandwritting','$merchantaccount','$customscripts','$creditcardprocessing','$searchengineoptimization',
					   '$searchcapabilitiesonthewebsite','$databaseprogramming','$budget','$time_start','$time_frame','$description',
					   '$referal';
?>
I want to go through the array and check to see if they are set. I was thinking like

Code: Select all

<?php
$variable2 == 0;

foreach($formvariables as $variable){ 

  if (isset($variable)){

  $variable2[$i]=true; }

$i++
} 

?>
Obviously this doesn't work but I'm just trying to plan everything out before I start coding away. Does anyone have an idea on how I can do this? This really isn't the best way to go at this anyways...

TY
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

You'll need to remove those single quotes around the vars in the array.
$variable2 == 0; should be just =
and you'll need to initialise $i, $i=0;
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

That isn't important at the moment, but thanks.

I'm really just looking for an alternative to doing what I had shown.

TY
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Ah, ok, well i think you're trying to do something like..

Code: Select all

$two = 'hello'; //to test it works
$array = array('one', 'two', 'three');
foreach($array as $arr){
  if(isset($$arr)){
    echo $arr.' is set<br />';
  } else {
    echo $arr.' isn''t set<br />';
  }
}
/*this outputs...
one isn't set
two is set
three isn't set
*/
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

K cool seems to look like what I need...when u said I need to remove the single quotes do you mean change them to double or remove them completely
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well, now i think i know what you're trying to do, then you want the single quotes, but remove the $
ie
$formvariables = array('type','type_other','logodesign','bannerdesign' .. etc..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

K seems to be fine... thanks alot mark :)

cheers
Post Reply