3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ThreePointStudio_CustomMarkupForUser_Constants { public static $availableMarkups = array( // Text Effects "bold" => array( "format" => array( array("span", array("style" => array("font-weight" => array("bold")))) ), ), "italic" => array( "format" => array( array("span", array("style" => array("font-style" => array("italic")))) ), ), "underline" => array( "format" => array( array("span", array("style" => array("text-decoration" => array("underline"))), array('mergeProperties' => true)) ), ), "overline" => array( "format" => array( array("span", array("style" => array("text-decoration" => array("overline"))), array('mergeProperties' => true)) ), ), "strike" => array( "format" => array( array("span", array("style" => array("text-decoration" => array("line-through"))), array('mergeProperties' => true)) ), ), "text_colour" => array( "format" => array( array("span", array("style" => array("color" => array("{_value}"))), array("variableFeed" => array("_value"))) ), ), "font_face" => array( "format" => array( array("span", array("style" => array("font-family" => array("{fontFamily}"))), array("variableFeed" => array("fontFamily"))) ), ), // Background and Borders "background_colour" => array( "format" => array( array("span", array("style" => array("background-color" => array("{_value}"))), array("variableFeed" => array("_value"))) ), ), "border" => array( "format" => array( array("span", array("class" => array("borderText"))) ), ), "border_colour" => array( "format" => array( array("span", array("style" => array("border-color" => array("{_value}"))), array("variableFeed" => array("_value"))) ), ), "border_style" => array( "format" => array( array("span", array("style" => array("border-style" => array("{borderStyle}"))), array("variableFeed" => array("borderStyle"))) ), ), ); public static $borderList = array( 0 => "none", 1 => "dotted", 2 => "dashed", 3 => "solid", 4 => "double", 5 => "groove", 6 => "ridge", 7 => "inset", 8 => "outset" ); // Mostly copied from http://www.ampsoft.net/webdesign-l/WindowsMacFonts.html public static $fontList = array( 0 => array("name" => "", "fullname" => "inherit"), 1 => array("name" => "Arial", "fullname" => 'Arial, Helvetica, sans-serif'), 2 => array("name" => "Arial Black", "fullname" => "'Arial Black', Gadget, sans-serif"), 3 => array("name" => "Comic Sans MS", "fullname" => "'Comic Sans MS', cursive, sans-serif"), 4 => array("name" => "Courier New", "fullname" => "'Courier New', Courier, monospace"), 5 => array("name" => "Georgia", "fullname" => 'Georgia, serif'), 6 => array("name" => "Impact", "fullname" => 'Impact, Charcoal, sans-serif'), 7 => array("name" => "Lucida Console", "fullname" => "'Lucida Console', Monaco, monospace"), 8 => array("name" => "Lucida Sans Unicode", "fullname" => "'Lucida Sans Unicode', 'Lucida Grande', sans-serif"), 9 => array("name" => "Palatino Linotype", "fullname" => "'Palatino Linotype', 'Book Antiqua', Palatino, serif"), 10 => array("name" => "Tahoma", "fullname" => 'Tahoma, Geneva, sans-serif'), 11 => array("name" => "Times New Roman", "fullname" => "'Times New Roman', Times, serif"), 12 => array("name" => "Trebuchet MS", "fullname" => "'Trebuchet MS', Helvetica, sans-serif"), 13 => array("name" => "Verdana", "fullname" => 'Verdana, Geneva, sans-serif'), ); public static $defaultOptionsArray = array( "username" => array(), "usertitle" => array() ); } $options = unserialize('a:2:{s:8:"username";a:9:{s:4:"bold";i:1;s:6:"italic";i:1;s:9:"underline";i:1;s:11:"text_colour";s:7:"#e01be0";s:9:"font_face";i:13;s:17:"background_colour";s:7:"#4683ab";s:6:"border";i:1;s:13:"border_colour";s:7:"#d91fd9";s:12:"border_style";i:1;}s:9:"usertitle";a:6:{s:4:"bold";i:1;s:6:"italic";i:1;s:9:"underline";i:1;s:6:"strike";i:1;s:8:"overline";i:1;s:9:"font_face";i:3;}}'); $sortedTags = $firstOccurrence = array(); foreach ($options["username"] as $optionName => $optionValue) { end($sortedTags); foreach (ThreePointStudio_CustomMarkupForUser_Constants::$availableMarkups[$optionName]["format"] as $tag) { $sortedTags[] = $tag; end($sortedTags); $index = key($sortedTags); $theTag = &$sortedTags[$index]; if (!in_array($theTag[0], $firstOccurrence)) { $firstOccurrence[$theTag[0]] = $index; } else { // Try to see if we can merge the properties if (isset($theTag[2]["loneTag"]) && $theTag[2]["loneTag"]) { // It wants it own tag continue; } $firstOccurrenceTag = &$sortedTags[$firstOccurrence[$theTag[0]]]; $intersection = array_keys(array_intersect_key($theTag[1], $firstOccurrenceTag[1])); if (in_array("style", $intersection)) { if ((isset($theTag[2]["mergeProperties"]) && $theTag[2]["mergeProperties"]) && (isset($firstOccurrenceTag[2]["mergeProperties"]) && $firstOccurrenceTag[2]["mergeProperties"])) { $firstOccurrenceTag[1]["style"] = array_replace_recursive($firstOccurrenceTag[1]["style"], $theTag[1]["style"]); } else { $firstOccurrenceTag[1]["style"] = array_replace($firstOccurrenceTag[1]["style"], $theTag[1]["style"]); } unset($theTag[1]["style"]); } if (in_array("class", $intersection)) { $firstOccurrenceTag[1]["class"] = array_replace($firstOccurrenceTag[1]["class"], $theTag[1]["class"]); unset($theTag[1]["class"]); } // Try to put anything that is not in the first occurrence tag into the first occurrence tag instead foreach ($theTag[1] as $attr => $attrValue) { if (!in_array($attr, array_keys($firstOccurrenceTag[1]))) { $firstOccurrenceTag[1][$attr] = $attrValue; unset($theTag[1][$attr]); } } if (empty($theTag[1])) { // No attr, drop the tag unset($sortedTags[$index]); end($sortedTags); continue; } // What is left is conflicted attributes. Leave as is in its own tag. } } } var_dump($sortedTags);

preferences:
58.66 ms | 402 KiB | 5 Q