Forum Moderators: coopster
Have you got any code started? As if not then you should have a look at mysql_query [uk2.php.net]or mysqli_query [uk2.php.net]. As these give good examples of what to do.
The difference in the 2 is minor. Try to use the mysqli versions if you have php5 as they are improved.
Welcome along.
dc
<?php
$membernumbers = file('mem_nums.txt', FILE_SKIP_EMPTY_LINES);
// Loop through our array, and display line numbers too.
foreach ($membernumbers as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . $line . "<br />\n";
}
?>
That's the code I'm using, but I don't understand it. How exactly does that loop work? What does
$membernumbers as $line_num mean? Where does it tell it which line of the array to print? print_r($membernumbers);
An array has key, value pairs.
If I did the foreach loop like this, you might understand it better:
foreach ($membernumbers AS $key => $value)
Its simply reading each slot into the variables $key & $value with each iteration. The good thing about a foreach loop is you can have random keys and it will still work. A for loop on the other hand would be checking for keys in numerical order and would therefore throw an error if a key was missing. Hope that makes sense.
The foreach loop will keep running until it hits the last slot and then it terminates.
Check out the PHP site for more info:
[uk2.php.net...]
dc