3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = array("/Expurgo", "/Famosos e Etc/Ego", "/Famosos e Etc/Ego/40 Graus", "/Famosos e Etc/Ego/40 Graus/Home", "/Famosos e Etc/Ego/Beleza", "/Famosos e Etc/Ego/Beleza/Home", "/Famosos e Etc/Ego/Carnaval", "/Famosos e Etc/Ego/Especiais/Avon", "/Famosos e Etc/Ego/Especiais/Dia das Maes", "/Famosos e Etc/Ego/Especiais/Lollapalooza", "/Famosos e Etc/Ego/Especiais/Lollapalooza/Home", "/Famosos e Etc/Ego/Especiais/Loreal", "/Famosos e Etc/Ego/Especiais/Malwee", "/Famosos e Etc/Ego/Especiais/Natal", "/Famosos e Etc/Ego/Especiais/Pascoa", "/Famosos e Etc/Ego/Especiais/Rock in Rio", "/Famosos e Etc/Ego/Especiais/Rock in Rio/Home", "/Famosos e Etc/Ego/Especiais/The Body Shop", "/Famosos e Etc/Ego/Gravidez", "/Famosos e Etc/Ego/Gravidez/Home", "/Famosos e Etc/Ego/Home", "/Famosos e Etc/Ego/Horoscopo", "/Famosos e Etc/Ego/Horoscopo/Home", "/Famosos e Etc/Ego/Moda", "/Famosos e Etc/Ego/Moda/Home", "/Famosos e Etc/Ego/Teen", "/Famosos e Etc/Ego/Teen/Home", "/Famosos e Etc/Home", "/G1/Agronegocios", "/G1/Agronegocios/Home", "/G1/Bem Estar", "/G1/Bem Estar/Home", "/G1/Blogs e Colunas", "/G1/Blogs e Colunas/Altieres Rohr", "/G1/Blogs e Colunas/Alysson Muotri", "/G1/Blogs e Colunas/Andrea Ramal", "/G1/Blogs e Colunas/Bruno Medina", "/G1/Blogs e Colunas/Cassio Barbosa", "/G1/Blogs e Colunas/Cristina Lobo", "/G1/Blogs e Colunas/Geneton Moraes Neto", "/G1/Blogs e Colunas/Luciano Trigo", "/G1/Blogs e Colunas/Paulo Coelho", "/G1/Blogs e Colunas/Redacao", "/G1/Blogs e Colunas/Ronaldo Prass", "/G1/Blogs e Colunas/Sergio Nogueira", "/G1/Blogs e Colunas/Startup", "/G1/Blogs e Colunas/Thais Heredia", "/G1/Blogs e Colunas/Viver Noronha", "/G1/Blogs e Colunas/Yvonne Maggie", "/G1/Blogs e Colunas/Zeca Camargo", "/GE", "/GE/Futebol", "/GE/Futebol/Especiais", "/GE/Futebol/Especiais/Home"); $return_array = array(); $temp_array = array(); foreach ($array as $key => $values) { echo substr($values, strrpos($values, "/"), -1) . "<br /><br />"; continue; $part = explode("/", $values); // Separa o ultimo noh $last_node = array_pop($part); // Se tem mais de um item junta o array if (count($part) > 1){ $parent_id = implode("/", $part); } else { // Senao pega a unica posicao $parent_id = $part[0]; } end($part); while ($level = prev($part)) { $return_array[] = array( "id" => $values, "parent" => $parent_id, "text" => $last_node ); } } echo json_encode($return_array);
based on 03JlD
Output for 5.2.0 - 7.2.0
/Expurg<br /><br />/Eg<br /><br />/40 Grau<br /><br />/Hom<br /><br />/Belez<br /><br />/Hom<br /><br />/Carnava<br /><br />/Avo<br /><br />/Dia das Mae<br /><br />/Lollapalooz<br /><br />/Hom<br /><br />/Lorea<br /><br />/Malwe<br /><br />/Nata<br /><br />/Pasco<br /><br />/Rock in Ri<br /><br />/Hom<br /><br />/The Body Sho<br /><br />/Gravide<br /><br />/Hom<br /><br />/Hom<br /><br />/Horoscop<br /><br />/Hom<br /><br />/Mod<br /><br />/Hom<br /><br />/Tee<br /><br />/Hom<br /><br />/Hom<br /><br />/Agronegocio<br /><br />/Hom<br /><br />/Bem Esta<br /><br />/Hom<br /><br />/Blogs e Coluna<br /><br />/Altieres Roh<br /><br />/Alysson Muotr<br /><br />/Andrea Rama<br /><br />/Bruno Medin<br /><br />/Cassio Barbos<br /><br />/Cristina Lob<br /><br />/Geneton Moraes Net<br /><br />/Luciano Trig<br /><br />/Paulo Coelh<br /><br />/Redaca<br /><br />/Ronaldo Pras<br /><br />/Sergio Nogueir<br /><br />/Startu<br /><br />/Thais Heredi<br /><br />/Viver Noronh<br /><br />/Yvonne Maggi<br /><br />/Zeca Camarg<br /><br />/G<br /><br />/Futebo<br /><br />/Especiai<br /><br />/Hom<br /><br />[]
Output for 5.0.0 - 5.1.6
/Expurg<br /><br />/Eg<br /><br />/40 Grau<br /><br />/Hom<br /><br />/Belez<br /><br />/Hom<br /><br />/Carnava<br /><br />/Avo<br /><br />/Dia das Mae<br /><br />/Lollapalooz<br /><br />/Hom<br /><br />/Lorea<br /><br />/Malwe<br /><br />/Nata<br /><br />/Pasco<br /><br />/Rock in Ri<br /><br />/Hom<br /><br />/The Body Sho<br /><br />/Gravide<br /><br />/Hom<br /><br />/Hom<br /><br />/Horoscop<br /><br />/Hom<br /><br />/Mod<br /><br />/Hom<br /><br />/Tee<br /><br />/Hom<br /><br />/Hom<br /><br />/Agronegocio<br /><br />/Hom<br /><br />/Bem Esta<br /><br />/Hom<br /><br />/Blogs e Coluna<br /><br />/Altieres Roh<br /><br />/Alysson Muotr<br /><br />/Andrea Rama<br /><br />/Bruno Medin<br /><br />/Cassio Barbos<br /><br />/Cristina Lob<br /><br />/Geneton Moraes Net<br /><br />/Luciano Trig<br /><br />/Paulo Coelh<br /><br />/Redaca<br /><br />/Ronaldo Pras<br /><br />/Sergio Nogueir<br /><br />/Startu<br /><br />/Thais Heredi<br /><br />/Viver Noronh<br /><br />/Yvonne Maggi<br /><br />/Zeca Camarg<br /><br />/G<br /><br />/Futebo<br /><br />/Especiai<br /><br />/Hom<br /><br /> Fatal error: Call to undefined function json_encode() in /in/0K7TT on line 88
Process exited with code 255.
Output for 4.4.5 - 4.4.9
/Expurg<br /><br />/Eg<br /><br />/40 Grau<br /><br />/Hom<br /><br />/Belez<br /><br />/Hom<br /><br />/Carnava<br /><br />/Avo<br /><br />/Dia das Mae<br /><br />/Lollapalooz<br /><br />/Hom<br /><br />/Lorea<br /><br />/Malwe<br /><br />/Nata<br /><br />/Pasco<br /><br />/Rock in Ri<br /><br />/Hom<br /><br />/The Body Sho<br /><br />/Gravide<br /><br />/Hom<br /><br />/Hom<br /><br />/Horoscop<br /><br />/Hom<br /><br />/Mod<br /><br />/Hom<br /><br />/Tee<br /><br />/Hom<br /><br />/Hom<br /><br />/Agronegocio<br /><br />/Hom<br /><br />/Bem Esta<br /><br />/Hom<br /><br />/Blogs e Coluna<br /><br />/Altieres Roh<br /><br />/Alysson Muotr<br /><br />/Andrea Rama<br /><br />/Bruno Medin<br /><br />/Cassio Barbos<br /><br />/Cristina Lob<br /><br />/Geneton Moraes Net<br /><br />/Luciano Trig<br /><br />/Paulo Coelh<br /><br />/Redaca<br /><br />/Ronaldo Pras<br /><br />/Sergio Nogueir<br /><br />/Startu<br /><br />/Thais Heredi<br /><br />/Viver Noronh<br /><br />/Yvonne Maggi<br /><br />/Zeca Camarg<br /><br />/G<br /><br />/Futebo<br /><br />/Especiai<br /><br />/Hom<br /><br /> Fatal error: Call to undefined function: json_encode() in /in/0K7TT on line 88
Process exited with code 255.
Output for 4.3.2 - 4.4.4
/Expurg<br /><br />/Eg<br /><br />/40 Grau<br /><br />/Hom<br /><br />/Belez<br /><br />/Hom<br /><br />/Carnava<br /><br />/Avo<br /><br />/Dia das Mae<br /><br />/Lollapalooz<br /><br />/Hom<br /><br />/Lorea<br /><br />/Malwe<br /><br />/Nata<br /><br />/Pasco<br /><br />/Rock in Ri<br /><br />/Hom<br /><br />/The Body Sho<br /><br />/Gravide<br /><br />/Hom<br /><br />/Hom<br /><br />/Horoscop<br /><br />/Hom<br /><br />/Mod<br /><br />/Hom<br /><br />/Tee<br /><br />/Hom<br /><br />/Hom<br /><br />/Agronegocio<br /><br />/Hom<br /><br />/Bem Esta<br /><br />/Hom<br /><br />/Blogs e Coluna<br /><br />/Altieres Roh<br /><br />/Alysson Muotr<br /><br />/Andrea Rama<br /><br />/Bruno Medin<br /><br />/Cassio Barbos<br /><br />/Cristina Lob<br /><br />/Geneton Moraes Net<br /><br />/Luciano Trig<br /><br />/Paulo Coelh<br /><br />/Redaca<br /><br />/Ronaldo Pras<br /><br />/Sergio Nogueir<br /><br />/Startu<br /><br />/Thais Heredi<br /><br />/Viver Noronh<br /><br />/Yvonne Maggi<br /><br />/Zeca Camarg<br /><br />/G<br /><br />/Futebo<br /><br />/Especiai<br /><br />/Hom<br /><br /> Fatal error: Call to undefined function: json_encode() in /in/0K7TT on line 88
Process exited with code 255.
Output for 4.3.0 - 4.3.1
/Expurg<br /><br />/Eg<br /><br />/40 Grau<br /><br />/Hom<br /><br />/Belez<br /><br />/Hom<br /><br />/Carnava<br /><br />/Avo<br /><br />/Dia das Mae<br /><br />/Lollapalooz<br /><br />/Hom<br /><br />/Lorea<br /><br />/Malwe<br /><br />/Nata<br /><br />/Pasco<br /><br />/Rock in Ri<br /><br />/Hom<br /><br />/The Body Sho<br /><br />/Gravide<br /><br />/Hom<br /><br />/Hom<br /><br />/Horoscop<br /><br />/Hom<br /><br />/Mod<br /><br />/Hom<br /><br />/Tee<br /><br />/Hom<br /><br />/Hom<br /><br />/Agronegocio<br /><br />/Hom<br /><br />/Bem Esta<br /><br />/Hom<br /><br />/Blogs e Coluna<br /><br />/Altieres Roh<br /><br />/Alysson Muotr<br /><br />/Andrea Rama<br /><br />/Bruno Medin<br /><br />/Cassio Barbos<br /><br />/Cristina Lob<br /><br />/Geneton Moraes Net<br /><br />/Luciano Trig<br /><br />/Paulo Coelh<br /><br />/Redaca<br /><br />/Ronaldo Pras<br /><br />/Sergio Nogueir<br /><br />/Startu<br /><br />/Thais Heredi<br /><br />/Viver Noronh<br /><br />/Yvonne Maggi<br /><br />/Zeca Camarg<br /><br />/G<br /><br />/Futebo<br /><br />/Especiai<br /><br />/Hom<br /><br /> Fatal error: Call to undefined function: json_encode() in /in/0K7TT on line 88