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 7533533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:45:12+00:00 2026-05-30T05:45:12+00:00

I am using smarty templating engine and am encountering a math issue. I am

  • 0

I am using smarty templating engine and am encountering a math issue. I am trying to create a total amount (sum) based on amounts in the array. (Normally I would do this at the server level, but do to the way that I create the array, dont think that is possible.) I am merging two arrays into one, but each array shares an ‘Amount’ which I am trying to determine the ‘Total Amount’

Here are the steps I am taking two arrays pushing into one array:

foreach ($data_main1 as $transaction_main1) {
    $json_decoded = json_decode($transaction_main1['NewObject']);
    $amount = $transaction_main1['Amount']; 
    $mycart1[] = array('ParentType' => $ParentType, 'Amount' => $amount);
    }

$mycart2=array();
foreach ($data_main2 as $transaction_main2) {
    $json_decoded = json_decode($transaction_main2['NewObject']);
    $amount = $transaction_main2['Amount'];
    $mycart2[] = array('ParentType' => $ParentType, 'Amount' => $amount);
    }


$mycart =  array_merge((array)$mycart1, (array)$mycart2);
$smarty->assign('cart', $mycart);

Here is my Smarty along with the math equation that does not show the value:

{assign var=last value=$cart[cart].Amount+1}

(I am certainly open to the idea of creating a total amount on the array_merge, just unsure how to do that, or even if it is possible)

  • 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-05-30T05:45:14+00:00Added an answer on May 30, 2026 at 5:45 am

    Do you know about the {math} Smarty bult-in function?

    {math equation="x + 1" x=$cart[cart].Amount}
    

    Let me know if it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using smarty for my site, and I'm trying to loop through an array
How can I limit the amount of loops through an array using Smarty? Let's
How can I get the total number of items in an array using Smarty?
I am using SMARTY and I need to create an array and assign value
On a PHP site using the smarty template engine (or at least a close
I'm currently using the Smarty templating system for our production site, but am curious
I'm trying to implements selection lists using Smarty and I'm aware of the {html_options}
I'm building a CodeIgniter application and using Smarty as my templating system. Instead of
I am using smarty as my template engine . I have a php result
I have following codes using smarty template engine In php file: $smarty->assign('SITE_URL', 'http://localhost/mis/'); In

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.