Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8622649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:06:32+00:00 2026-06-12T07:06:32+00:00

Hello I have a basic php script which is used to display the price

  • 0

Hello I have a basic php script which is used to display the price of a group of items in an array. The array has 3 pieces of information: name, price, and sku. The price could be set to something like 99.95, 12.95, 10.50 or just 5.00. Everything seems to work well so far, but when I try to report any price like 5.00 or 10.00 (whole dollar amounts) it just truncates the ending .00, which isnt exactly a problem but I would rather have it display the trailing zeros so everything looks nice and similar. Here is the code for the array/reporting loop:

$items = Array
    (
            "0"=> Array
            (
                "name" => $_SESSION['itemname-mo'],
                "price" => $_SESSION ['price-mo'],
                "sku" => $_SESSION ['sku-mo']
            ),
            "1" => Array
            (
                "name" => $_SESSION['itemname-addon'],
                "price" => $_SESSION ['price-addon'],
                "sku" => $_SESSION ['sku-addon']
            ),
            "2" => Array
            (
                "name" => $_SESSION['itemname-addon1'],
                "price" => $_SESSION ['price-addon1'],
                "sku" => $_SESSION ['sku-addon1']
            ),
            "3" => Array
            (
                "name" => $_SESSION['itemname-addon2'],
                "price" => $_SESSION ['price-addon2'],
                "sku" => $_SESSION ['sku-addon2']
            )

        );

    $a_length = count($items);

    for($x = 0; $x<$a_length; $x++){
    $total +=$items[$x]['price']; 
    }
    echo "<div class=\"well\">";
    for($i = 0; $i < $a_length; $i++){
    $name = $items[$i]['name'];
    $price = $items[$i]['price'];
    $sku = $items[$i]['sku'];
    displaycart($name,$price,$sku);
    }
    echo "<br />
    Sub Total: 
    $$total";
    echo "</div>";

        function displaycart($name,$price,$sku){

            if($name != null || $price != null || $sku != null){
                echo "$name: $$price ($sku) <br />";
            }
            else{ echo "";}
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:06:33+00:00Added an answer on June 12, 2026 at 7:06 am

    See number_format.

    number_format($number, 2, '.', '');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im new to php. I have a basic unlink php file which deletes a
Possible Duplicate: Sorting an associative array in PHP Hello all, I have an array
Dup of Some Basic PHP Questions Hello, I have a heap of tinyint fields
I have basic hello word example of Prime Faces. I have created dynamic web
Question I have a fairly static website with just a few basic PHP usage.
Introduction Hello. I am a newbie to PHP programming. I have know the basics
I am new to PHP, so I have a basic question. I have this
I have a basic Java program with output of hello world. What I want
My web hosting company has upgraded PHP to version 5.4.7. I have no choice
Hello I have a couple questions about PHP exec() and passthru(). 1) I never

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.