3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Demo { public function __construct(private string $val) { } public function get_sku() { return [ 'abc' => 1, 'def' => 2, 'ghi' => 3, 'jkl' => 4, ][$this->val]; } } $cart = (object) [ 'cart_contents' => [ ['data' => new Demo('ghi')], ['data' => new Demo('def')], ['data' => new Demo('jkl')], ['data' => new Demo('abc')], ] ]; $skus = []; $items_to_sort = []; foreach ($cart->cart_contents as $item ) { $skus[] = $item['data']->get_sku(); } array_multisort($skus, $cart->cart_contents); var_export($cart->cart_contents);
Output for git.master_jit, git.master, rfc.property-hooks
array ( 0 => array ( 'data' => \Demo::__set_state(array( 'val' => 'abc', )), ), 1 => array ( 'data' => \Demo::__set_state(array( 'val' => 'def', )), ), 2 => array ( 'data' => \Demo::__set_state(array( 'val' => 'ghi', )), ), 3 => array ( 'data' => \Demo::__set_state(array( 'val' => 'jkl', )), ), )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
38.53 ms | 406 KiB | 5 Q