3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // inside a class method $quotes = $this->listQuotes(); // $quotes now contains a list of quotes: // var_dump($quotes) will output something like: // array (size=26) // 0 => // array (size=23) // 'order_number' => string '12345678' (length=8) // 'customer_number' => string '111111' (length=6) // 'status' => string 'active' (length=6) // 'expired_date' => string '2017-08-06' (length=10) // 'quote_total' => float 24.61 // 'lineitems' => // array (size=0) // empty // 1 => // array (size=23) // ... // PROBLEM: I need to add an element to each of the arrays called grand_total // The output should then look something like this: // // array (size=26) // 0 => // array (size=23) // 'order_number' => string '12345678' (length=8) // 'customer_number' => string '111111' (length=6) // 'status' => string 'active' (length=6) // 'expired_date' => string '2017-08-06' (length=10) // 'quote_total' => float 24.61 // 'lineitems' => // array (size=0) // empty // 'grand_total' => array(size=2) // 'tax_inclusive' => float 123.45 // 'tax_exclusive' => float 120.00 // ] // 1 => // array (size=23) // ... // Routine would be something like $quotes = $this->listQuotes(); array_walk($quotes, function($quote, $key) { $quote['grand_total'] = [ 'tax_inclusive' => 123.45, 'tax_exclusive' => 120.00 ] }); // Then var_dump($quotes) *should* give me the expected described as above... // // I've tried with array_walk, array_map, and even a foreach. No errors setting the value, but the original list that gets returned is unchanged.
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.1.7
Parse error: syntax error, unexpected '}' in /in/daMKh on line 52
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught Error: syntax error, unexpected '}' in /in/daMKh:52 Stack trace: #0 {main}
Process exited with code 255.