Solved

PHP

Posted on 2003-10-28
5
311 Views
Last Modified: 2010-04-07
Hi everyone, I hope this is an easy one – I would simply like to combine a bunch of PHP functions into one script.  Here is the architecture:

1) I send a PHP script a series of variables that have a value.  If these variables have a value, PHP fires a script:

varA=1
varB=2
varC=3
varD=4
…and so on (a total of 30 variables in sequential order)

2) If varA = ‘something’ then do the following:
<?
$file = fopen("./Folder/" . "NewFile1", "w");
fwrite($file,"$varA");
fclose($file);
?>

If varB = ‘somehting’ then do the following:
<?
$file = fopen("./Folder/" . "NewFile2", "w");
fwrite($file,"$varB");
fclose($file);
?>

This is repeated all the way down to the 30th variable.

Hope this is easy.
0
Comment
Question by:Donavan_usa
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
mleeb earned 400 total points
ID: 9648776
1. Simply form an array of the variables.
2. Obtain the length of the array.
3. Run a for loop on the array of variables.
4. Test that the current variable has a value.
5. Perform file creation function.
6. Continue looping until complete.

$varA = 1;
$varB = 2;
$varC = 3;

$arrayName = array ($varA, $varB, $varC);
$arrayLength = count($arrayName);

for ($i = 0; $i < $arrayLength; $i++)
{
     if($arrayName[$i] != '')
     {
      $file = fopen("Folder/NewFile$arrayName[$i]", "w");
      fwrite($file, "$arrayName[$i]");
      fclose($file);
     }
}
?>  
0
 

Author Comment

by:Donavan_usa
ID: 9651109
Thanks mleeb, I will try out your above code.

Cheers.
0
 

Author Comment

by:Donavan_usa
ID: 10416468
Sorry for delay - what if there is an unlimited number of variables coming in?

Cheers
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now