View Single Post
Old Nov 20th, 2007, 8:04 AM   #1
davil
Newbie
 
Join Date: Nov 2007
Posts: 27
Rep Power: 0 davil is on a distinguished road
Simple "foreach" problem

Ok so I'm getting into PHP and I have a decent sized MySQL/PHP database system working fine but I'm having problems with the foreach command...

When I get the info from a MySQL database I usually use the following command to assign a variable to each value:

php Syntax (Toggle Plain Text)
  1. foreach ($row as $key => $value) {$$key = $value;}

This works perfectly but I was wondering is there a way to check something like $datestamp vs $new_datestamp and $timestamp vs $new_timestamp by doing something like this code below?

php Syntax (Toggle Plain Text)
  1. foreach ($row as $key => $value) {
  2. $$key = $value;
  3. if ($new_$$key==$$key){echo "$new_$$key is same as old $$key, which is $value\n";
  4. }


I know this doesn't work above but I'm presuming it's something to do with my syntax... I've had a look at PHP.net tutorials and done a bit of googling but I'm lost on this simplest of all problems...

I could do it the long way with like 20 conditions but I want to get more efficient in my programming.
davil is offline   Reply With Quote