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

  • Home
  • SEARCH
  • 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 7677549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:26:51+00:00 2026-05-31T17:26:51+00:00

I’m currently making a PHP-program that solves equations. I’ve divided the input equation into

  • 0

I’m currently making a PHP-program that solves equations. I’ve divided the input equation into an array so that each line in the array contains one term. (So. [0] = “+5x”, [1] = “=”, [2] = “-5”, [3] = “+10”. This is just a basic equation. The script also divides what is in () into sub-arrays. So for example 2x+(5-3x)=3(x+1) [0] = “+2*x”, [1] = array([0] = “+5″….

However, I discovered expression trees that is the perfect thing to use in this equation-solver. I’ve searched the whole internet to learn it, but I can’t find any websites that explain it in PHP (I know PHP OOP.). There are lots of pages explaining them in for example C, but as I only know PHP, that is of no help, because I don’t understand the example code.

Can anyone here explain everything about expression trees in PHP and some practical example code?

  • 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-31T17:26:52+00:00Added an answer on May 31, 2026 at 5:26 pm

    Here is the algorithm described. you can implement this in PHP. I don’t think anyone already implemented this in PHP (and distribute it as open source)

    An example would be:

    2*x+3*5-(6+9) = 0
    

    Where:

    • * = priority 2
    • + = priority 1
    • ( = will increase priority of signs by 10
    • + (second +) = priority 11
    • ) = will decrease priority of signs by 10
    • = = in this case it is showing that there is another expression (0)

    The highest priority is the most important – the one you need to do first

    Using these rules you can create an expression tree…

    So.. a way in which you have to create the expression and then interpret is:

    2 x * 3 5 * + 6 9 + -
    

    Explained:

    • 2 * x | (1)
    • 3 * 5 | (2)
    • (1) + (2) | (3)
    • 6 + 9 | (4)
    • (3) - (4) = final

    I don’t remember exactly how to write a tree I did this to a course in Computer Science but it was something like this:

                                         -
                                    /         \
                                    E         (E)
                                    |          +
                                    +         / \
                                 /    \      6   9
                                E      E        
                                |      |    
                                *      *
                               / \    / \    
                              T   E   T  E
                              |   |   |  |
                              2   T   3  T
                                  |      |
                                  x      5
    

    Now you have to create your own interpreter for this. You can use the interpreter pattern: PHP Interpreter

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.