Question : Quoting array names in Associative Arrays in PHP in assignment and echo statements.

This is a bit of annoying problem.  I am fixing up some sites that have statements like this:

      while( $row=mysql_fetch_array($result) )
      {
            $prty_id=$row[prty_id];
            $prty_title=$row[prty_title];
            $prty_type=$row[prty_type];
            $prty_bedrooms=$row[prty_bedrooms];
            $prty_baths=$row[prty_baths];
            $prty_long_description=$row[prty_long_description];
            $prty_sleeps=$row[prty_sleeps];
            $prty_floors=$row[prty_floors];
            $prty_price_per_night=$row[prty_price_per_night];
            $prty_rates=$row[prty_rates];
            $prty_amenities=$row[prty_amenities];
            $prty_close_to=$row[prty_close_to];
            $prty_pets=$row[prty_pets];
            $prty_smoking=$row[prty_smoking];
            $prty_handicapped=$row[prty_handicapped];
            $prty_kid_friendly=$row[prty_kid_friendly];
            $prty_credit_cards=$row[prty_credit_cards];
            $prty_rating=$row[prty_rating];
            $prty_hits_to_date=$row[prty_hits_to_date]+1;
            $prty_calendar_id= $row[prty_calendar_id];
            $id_ref_external = $row[prty_calendar_id];
            $prty_display_id=$row[prty_display_id];
      }

and this:

echo "\n<a href=\"javascript:;\" onclick='return openWindow($prty_id,$i,$imgAncho,$imgAlto);' onmouseover=\"MM_swapImage('mainpic','','./generar_imagen.php?imagen=./images/properties/$row_photo[pht_photo]&amp;ancho=300&amp;alto=200',1)\" onmouseout=\"\">";

On my hosting service server this doesn't cause any problems, I think because "notices" are turned off.  On my home server (MAMP on OS X), I have notices and worse turned on.  I am getting NOTICE errors because the argument is not quoted, which isn't a problem in the first set as I can quote those easily.  In the second statement I've been resorting to something like this:

echo "\n<a href=\"javascript:;\" onclick='return openWindow($prty_id,$i,$imgAncho,$imgAlto);' onmouseover=\"MM_swapImage('mainpic','','./generar_imagen.php?imagen=./images/properties/".$row_photo['pht_photo']."&amp;ancho=300&amp;alto=200',1)\" onmouseout=\"\">";

Just wondering if that is necessary and if there is a server setting that would ignore that.  It seems to be working fine on my hosting service and I guess assumes that the argument should be/is quoted.

Kind of a pain to go through everything and add quotes.

Along those lines, is the a RegExp that would fix that generally?

i.e.  Replace $array[string] with $array['string'] when it isn't in an echo statement and replace $array[string]  with:

".$array['string'] ." when it is in an echo statement.

What is the best practice as far as that is concerned.  Given that I am getting a warning I guess you should be using the quotes.

Answer : Quoting array names in Associative Arrays in PHP in assignment and echo statements.

The area under the curve would be the cumulative people impact over time.  Unfortunately, there isn't a general relationship between people and time.  (In the case of speed vs time... in a linear function, speed * time = distance.)

If population represented a drain of resources, you could consider the area under the curve as the total resources consumed by people...

If each unit of time were 'lifespan', the area under the curve would be 'corpses'.
Random Solutions  
 
programming4us programming4us