如何使用键和值来爆炸数组多维

I have string like this:

$string = Leader,Brian; Elder,Nina,Maria; Member,Duke,Rai,Mike

What I've done:

$explode = ("; ", $string);

Then will show it, like:

Array ([0] => Leader,Brian [1] => Elder,Nina,Maria [2] => Member,Duke,Rai,Mike)

But I want not like that. I want make it to be array mutlidimentional with key and value, like this:

Array ([Leader] => Brian [Elder] => Array ([0] => Nina [1] => Maria) 
       [Member] => Array ([0] => Duke [1] => Rai [2] => Mike))

Then, How to show it's in table tag html like this?

Leader  |  Brian
Elder   |  Nina
        |  Maria
Member  |  Duke
        |  Rai
        |  Mike 

thank you for your attention
NB: You can change the separator in string if it's difficult with separator like that

Youre explode is a good first step.

Next one is to iterate its result and explode it again. Then (in the same loop) use first element of the second explode's result as key and the rest as value.

$string = "Leader,Brian; Elder,Nina,Maria; Member,Duke,Rai,Mike";

$exploded = explode("; ", $string);

foreach($exploded as $element) {
    $arr = explode(',', $element);

    $result[array_shift($arr)] = $arr;
}

var_dump($result);

Result:

array(3) {
  ["Leader"]=>
  array(1) {
    [0]=>
    string(5) "Brian"
  }
  ["Elder"]=>
  array(2) {
    [0]=>
    string(4) "Nina"
    [1]=>
    string(5) "Maria"
  }
  ["Member"]=>
  array(3) {
    [0]=>
    string(4) "Duke"
    [1]=>
    string(3) "Rai"
    [2]=>
    string(4) "Mike"
  }
}

I would probably walk the array after splitting the string and split again:

$list = explode("; ", $string);
array_walk($list, function(&$element) {
    $names = explode(',', $element);
    // Take the first item off the array type
    $type = array_shift($names);
    // Alter the array in-place to create the sub-array
    $element = [$type => $names]
});

You need two "explodes"

$string = 'Leader,Brian; Elder,Nina,Maria; Member,Duke,Rai,Mike';
$explode = explode("; ", $string);
foreach($explode as $row){
    $explode2 = explode(",", $row);
    foreach($explode2 as $i=>$p ){

        echo ( $i > 0 )?"
\t|":"
";
        echo $p;
    }
}

You need to explode twice - on your two delimiters, for example:

<?php
$string = "Leader,Brian; Elder,Nina,Maria; Member,Duke,Rai,Mike";

$result = array();
$parts = explode(";", $string);

foreach ($parts as $part)
{
    $kv = explode(",", $part);
    $result[array_shift($kv)] = $kv;
}

// result:
echo '<pre>';
print_r($result);
echo '</pre>';
?>

Will give you:

Array
(
    [Leader] => Brian
    [Elder] => Nina
    [Member] => Duke
)

This should do it:

<?php
$string = 'Leader,Brian; Elder,Nina,Maria; Member,Duke,Rai,Mike';

$explode = array_map(function($v){return explode(',', $v);}, explode(';', $string));

$new_array = [];

foreach($explode as $k=>$v)
{
    $v[0] = trim($v[0]);

    $new_array[$v[0]] = $v;

    unset($new_array[$v[0]][0]);

    $new_array[$v[0]] = array_values($new_array[$v[0]]);
}

print_r($new_array);