3v4l.org

run code in 500+ PHP versions simultaneously
<?php $variations = [ "sku" => [ 0 => "dSADad", 1 => "ASDAF", 2 => "ASFAS", // ... ], "Price" => [ 0 => "1", 1 => "1", 2 => "1", // ... ], "Quantity" => [ 0 => "123", 1 => "123", 2 => "123434", // ... ], "attributes" => [ "Color" => [ 0 => "5", 1 => "4", 2 => "4", // ... ], "Size" => [ 0 => "3", 1 => "3", 2 => "2", // ... ], "Material" => [ 0 => "7", 1 => "7", 2 => "8", // ... ], ], ]; function extractVariation($variations, $key) { $variation = []; foreach ($variations as $property => $values) { if (isset($values[$key])) { $variation[$property] = $values[$key]; } else { $variation[$property] = extractVariation($values, $key); } } return $variation; } $newVariations = []; foreach ($variations['sku'] as $key => $sku) { $newVariations[] = extractVariation($variations, $key); } var_export($newVariations);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'sku' => 'dSADad', 'Price' => '1', 'Quantity' => '123', 'attributes' => array ( 'Color' => '5', 'Size' => '3', 'Material' => '7', ), ), 1 => array ( 'sku' => 'ASDAF', 'Price' => '1', 'Quantity' => '123', 'attributes' => array ( 'Color' => '4', 'Size' => '3', 'Material' => '7', ), ), 2 => array ( 'sku' => 'ASFAS', 'Price' => '1', 'Quantity' => '123434', 'attributes' => array ( 'Color' => '4', 'Size' => '2', 'Material' => '8', ), ), )

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:
55.09 ms | 1201 KiB | 4 Q