Heim > Backend-Entwicklung > PHP-Tutorial > 重组数组,实现类似淘宝一样的合并订单

重组数组,实现类似淘宝一样的合并订单

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-06 20:13:31
Original
915 Leute haben es durchsucht

<code>array (
  '0' =>
    array (
      'id' => string '22',
      'title' => string '商品名称',
      'test' => string '123',
      )
  '1' =>
    array (
      'id' => string '23',
      'title' => string '商品名称',
      'test' => string '125',
      )
  '2' =>
    array (
      'id' => string '30',
      'title' => string '商品名称',
      'test' => string '123',
      )
)</code>
Nach dem Login kopieren
Nach dem Login kopieren

类似上面的数组,需要把test字段相同的组合在一起,并在前台输出,类似电商网站的订单合并,在线等

回复内容:

<code>array (
  '0' =>
    array (
      'id' => string '22',
      'title' => string '商品名称',
      'test' => string '123',
      )
  '1' =>
    array (
      'id' => string '23',
      'title' => string '商品名称',
      'test' => string '125',
      )
  '2' =>
    array (
      'id' => string '30',
      'title' => string '商品名称',
      'test' => string '123',
      )
)</code>
Nach dem Login kopieren
Nach dem Login kopieren

类似上面的数组,需要把test字段相同的组合在一起,并在前台输出,类似电商网站的订单合并,在线等

其实很简单:

<code>$arra =   array (
            '0' => array ('id' =>  '22', 'title' =>  '商品名称', 'test' =>  '123',),
  '1' => array ('id' =>  '23', 'title' =>  '商品名称', 'test' => '125',),
  '2' => array ('id' =>  '30', 'title' =>  '商品名称', 'test' =>  '123',));
        $result = array();
        foreach($arra as $key => $value){
            $result[$value['test']][] = $value;
        }</code>
Nach dem Login kopieren

结果是一个三维数组

Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
PHP-Datenerfassung?
Aus 1970-01-01 08:00:00
0
0
0
PHP-Erweiterung intl
Aus 1970-01-01 08:00:00
0
0
0
Wie man PHP gut lernt
Aus 1970-01-01 08:00:00
0
0
0
Mehrere PHP-Versionen
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage