Jump to content

padana

New Members
  • Posts

    4
  • Joined

  • Last visited

Posts posted by padana

  1. But for the expression I can't access the table in a table: 

    $expression2 = [
        "type" => "add",
        'children' => [
            [
                "type" => "number",
                "value" => 100
            ],
            [
                "type" => "multiply",
                "children" => [
                    [
                        "type" => "number",
                        "value" => 2
                    ],
                    [
                        "type" => "add",
                        "children" => [
                            [
                                "type" => "number",
                                "value" => 5
                            ],
                            [
                                "type" => "number",
                                "value" => 45
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ];

     

  2. <?php
    
    function evaluate($expression)
    {
        // TODO : add rendering code here
    
       
    }
    
    // 100 + 200 + 300
    $expression1 = [
        "type" => "add",
        'children' => [
            [
                "type" => "number",
                "value" => 100
            ],
            [
                "type" => "number",
                "value" => 200
            ],
            [
                "type" => "number",
                "value" => 300
            ]
        ]
    ];
    
    // 100 + 2 * (45 +5)
    $expression2 = [
        "type" => "add",
        'children' => [
            [
                "type" => "number",
                "value" => 100
            ],
            [
                "type" => "multiply",
                "children" => [
                    [
                        "type" => "number",
                        "value" => 2
                    ],
                    [
                        "type" => "add",
                        "children" => [
                            [
                                "type" => "number",
                                "value" => 5
                            ],
                            [
                                "type" => "number",
                                "value" => 45
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ];
    
    
    
    // 1 + 100 / 1000
    $expression3 = [
        "type" => "add",
        'children' => [
            [
                "type" => "number",
                "value" => 1
            ],
            [
                "type" => "fraction",
                "top" =>
                [
                    "type" => "number",
                    "value" => 100
                ],
                "bottom" =>
                [
                    "type" => "number",
                    "value" => 1000
                ]
            ]
        ]
    ];
    
    echo "Expression 1 evaluates to: " . evaluate($expression1) . " <br>";
    
    echo "Expression 2 evaluates to: " . evaluate($expression2) . " <br>"
     
    echo "Expression 3 evaluates to: " . evaluate($expression3) . " <br>"

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.