Solved

PHP

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. 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 : Go t…

863 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

20 Experts available now in Live!

Get 1:1 Help Now