I've had this issue from the first series with Randy, "Build a Simple PHP Application", that in my $products array, for the variable $price, if I don't actually enter a Dollar Sign ($) with "Quotes" around the value, I don't get a "Price" in my browser-- Just a big Number Value, that a user/visitor would have to guess its meaning. (In Randy's browser he's never had this issue & it hasn't come up.
I'm going to include the code which has my "solution" along with the original code commented out
$products = array( "name" => "Mike the Frog Shirt, Blue", "img" => "img/shirts/shirt-103.jpg", // "price" => 20, << ===== = ---- -- -- - - - - ?!! "price" => "$20", "paypal" => "7T8LK5WXT5Q9J", "sizes" => array("Small","Medium","Large","X-Large") );
it has become an issue because now the page is getting all this info from the database (utterly new stuff to me) & I lack even a shred of insight into resolving this.
Interesting question? i hope so. Please and Thank You!
Vittorio Somaschini33,371 Points
I do not think your solution is ideal as writing the code the way you did will mean that "$20" will come out as a string, while with the price you would normally need to treat is as a number, let's say an integer. So I would try to sort it in a different way, but I haven't really understood what happens if you just do "price" => 20, on that line.
Could you please be more specific?
This are the lines in my shirt.php file that display the price:
<div class="shirt-details"> <h1><span class="price">$<?php echo $product["price"]; ?></span> <?php echo $product["name"]; ?></h1> I add the dollar sign here, and I suspect somewhere in the css file the class "price" formats the integer into a standard dollar amount.