Solved

PHP

Posted on 2003-10-28
5
319 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
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 Import and export files in WordPress. 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 : Click on Too…

839 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