显示在html表中的键对值。 密钥应该是标题[关闭]

I have the following array In php:

$values=[
          [
            ['key'=>"Name",'value'=>"John"],
            ['key'=>'Surname','value'=>"Doe"],
            ['key'=>"email",'value'=>'john@doe.com']
          ],
          [
            ['key'=>"Surname",'value'=>"Ichigo"], 
            ['key'=>'Name','value'=>"Kurosaki"],
            ['key'=>'email','value'=>'kurosakiighogo@soulsociety.com']
          ],
          [
            ['key'=>"email",'value'=>"monket.d@luffy.com"],
            ['key'=>'Name','value'=>"Monkey D."],
            ['key'=>'Surame','value'=>'Luffy']
          ],
        ];

And I want somehow to be generated as:

$values2=[
         head=>['Name','Surname','email'],
         values=>[
                   ["John","Doe","john@doe.com"],
                   ["Kurosaki","Ichigo","kurosakiighogo@soulsociety.com"],
                   ['Monkey D.','Luffy','monket.d@luffy.com']
                 ]
        ]

The key point I want is on head to be stored the keys and on values the values. But with the same Order.

To be specific on values[$i][$j] I want to be stored the $values['value'] where $values['key'] === head[j].

The problem is NOT HOW TO DISPLAY the array $values2 but HOW TO TRANSFORM $values array into $values2.

I want a bit of your help please.

Try this ;)

$values = [
  [
    ['key'=>"Name",
      'value'=>"John"],
    ['key'=>'Surname',
      'value'=>"Doe"],
    ['key'=>"email",
      'value'=>'john@doe.com']
  ],
  [
    ['key'=>"Surname",
      'value'=>"Ichigo"],
    ['key'=>'Name',
      'value'=>"Kurosaki"],
    ['key'=>'email',
      'value'=>'kurosakiighogo@soulsociety.com']
  ],
  [
    ['key'=>"email",
      'value'=>"monket.d@luffy.com"],
    ['key'=>'Name',
      'value'=>"Monkey D."],
    ['key'=>'Surname',
      'value'=>'Luffy']
  ],
];

$records = [];
$keyIndex = [];
foreach($values as $index=> $record){
  $thisRecord = [];
  foreach($record as $index1=> $field){
    if(!$index){
      $keyIndex[$field['key']] = $index1;
      $records['head'][] = $field['key'];
    }
    $thisRecord[$keyIndex[$field['key']]] = $field['value'];
  }
  ksort($thisRecord);
  $records['values'][] = $thisRecord;
}