Simple PHP problem, please help

Vicken

Senior member
Oct 10, 1999
381
0
0
I am new to PHP and I have a problem which I am trying to figure out.

Say a user inputted 5 strings in a form. Some of these strings can be null.

What I want to do is find out which ones are NOT null and print out the string name and value.

like this

5 strings = A B C D E

User inputs 5 for A, and 4 for E

program will output this

A 5

E 4

I want to use arrays instead of a million if then statements.

How is this done?
 

Hullboy

Member
Apr 18, 2001
172
0
0
Vicken

Try something like a for loop:

create two arrays to represent the letters and the numbers input by the users

$a[] = A
$a[] = B etc

and another for the values to be associated with A, B etc.

$b[] = user value etc

let the user input the values (probably construct a loop for this too)

then print them out if they have a value:

for ($i = 0;$i <=5;$i++)
{
if (!empty($b[$i]) print ("You assigned %s to value %s", $a[$i], $b[$i]);
}