PHP PHP - 6 months ago 21
PHP Question

how to implode this pattern to array?

i want implode this txt pattern to Multidimensional Arrays and echo array into table

My pattern :<

group1&john,www.johnsite.com]jack,www.jacksite.com]jorge,www.jorgesite.com^group2&Ivan,www.ivansite.com]Dan,www.dansite.com]Ted,wwww.tedsite.com^


i want echo this pattern like this (dont show website address)

Group1: john-jack-jorge

Group2: Ivan-Dan-Ted

Answer

Try this:

$str = "group1&john,www.johnsite.com]jack,www.jacksite.com]jorge,www.jorgesite.com^group2&Ivan,www.ivansite.com]Dan,www.dansite.com]Ted,wwww.tedsite.com^";

$str = trim($str, "^");
$groups = explode("^", $str);

foreach($groups as $val){
    $group = ucfirst(explode("&", $val)[0]);
    $arr = explode("]", explode("&", $val)[1]);
    $name = array();
    foreach($arr as $v)
        $name[] = explode(",", $v)[0];
    $name = implode("-", $name);
    echo $group.": ".$name."<br/>";
}