Jump to content

padana

New Members
  • Posts

    4
  • Joined

  • Last visited

padana's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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. here for expression1 I found the result: $var1 = $expression['children'][0]['value']; $var2 = $expression['children'][1]['value']; $var3 = $expression['children'][2]['value']; return $var1 + $var2 + $var3; result: 600
  3. yes it's a duty I am blocked. Because I want to get the value back but he gives me that foreach ($expression as $i) { $var1 = var_dump($i[0]["value"]); $var2 = var_dump($i[1]["value"]); $var2 = var_dump($i[2]["value"]); result: Warning: Illegal string offset 'value'
  4. <?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.