Как из массива сделать таблицу

172
25 февраля 2019, 17:10

Как из этого массива сделать таблицу как на рисунке?

 Array
 (
     [0] => Array
         (
             [code] => ru
             [created] => 1539766312218
             [name] => Русский
             [ownerId] => 
             [updated] => 1539859934434
             [objectId] => 0E5BD427-7883-903C-FFDD-2309E2D79800
             [___class] => langs
             [property] => Array
                 (
                     [0] => Array
                         (
                             [created] => 1539766406514
                             [lang_id] => 0E5BD427-7883-903C-FFDD-2309E2D79800
                             [listorder] => 1
                             [ownerId] => 
                             [word] => man
                             [updated] => 1539878678826
                             [objectId] => 08F5A487-7649-BB93-FFC0-83C4F37BB500
                             [translate] => Человек
                             [___class] => lang_values
                         )
                     [1] => Array
                         (
                             [created] => 1539790314249
                             [lang_id] => 0E5BD427-7883-903C-FFDD-2309E2D79800
                             [listorder] => 1
                             [ownerId] => 
                             [word] => mother
                             [updated] => 1539878675079
                             [objectId] => 13518375-E50B-91F7-FFFF-AC72CF60FA00
                             [translate] => Мать
                             [___class] => lang_values
                         )
                 )
         )
     [1] => Array
         (
             [code] => es
             [created] => 1539801591893
             [name] => Español
             [ownerId] => 
             [updated] => 1539859937333
             [objectId] => 28106D56-CCD4-557D-FF8F-58D48189F000
             [___class] => langs
             [property] => Array
                 (
                     [2] => Array
                         (
                             [created] => 1539801850966
                             [lang_id] => 28106D56-CCD4-557D-FF8F-58D48189F000
                             [listorder] => 1
                             [ownerId] => 
                             [word] => man
                             [updated] => 1539878651249
                             [objectId] => 17BFA8F1-2E97-79BE-FF56-6556F997C300
                             [translate] => Un hombre
                             [___class] => lang_values
                         )
                 )
         )
     [2] => Array
         (
             [code] => de
             [created] => 1539766491804
             [name] => Deutsch
             [ownerId] => 
             [updated] => 1539859935404
             [objectId] => 79F70774-58BB-7D1C-FF4A-783DABF25C00
             [___class] => langs
             [property] => Array
                 (
                     [4] => Array
                         (
                             [created] => 1539766435042
                             [lang_id] => 79F70774-58BB-7D1C-FF4A-783DABF25C00
                             [listorder] => 1
                             [ownerId] => 
                             [word] => man
                             [updated] => 1539878692087
                             [objectId] => 6F728A08-0038-6763-FFB6-E87B96075500
                             [translate] => ein Mann
                             [___class] => lang_values
                         )
                 )
         )
     [3] => Array
         (
             [code] => en
             [created] => 1539801538374
             [name] => English
             [ownerId] => 
             [updated] => 1539859936392
             [objectId] => B7B0995E-8BCF-B2AA-FF92-CAB4B7DD4E00
             [___class] => langs
             [property] => Array
                 (
                     [3] => Array
                         (
                             [created] => 1539801786691
                             [lang_id] => B7B0995E-8BCF-B2AA-FF92-CAB4B7DD4E00
                             [listorder] => 1
                             [ownerId] => 
                             [word] => man
                             [updated] => 1539878701290
                 [objectId] => 6D6B991A-FCC3-4C32-FFA5-0F3ACA54D400
                             [translate] => Man
                             [___class] => lang_values
                         )
                 )
         )
 )

Массив через var_export

0 => 
array (
'code' => 'ru',
'created' => 1539766312218,
'name' => 'Русский',
'ownerId' => NULL,
'updated' => 1539859934434,
'objectId' => '0E5BD427-7883-903C-FFDD-2309E2D79800',
'___class' => 'langs',
'property' => 
array (
  0 => 
  array (
    'created' => 1539766406514,
    'lang_id' => '0E5BD427-7883-903C-FFDD-2309E2D79800',
    'listorder' => 1,
    'ownerId' => NULL,
    'word' => 'man',
    'updated' => 1539878678826,
    'objectId' => '08F5A487-7649-BB93-FFC0-83C4F37BB500',
    'translate' => 'Человек',
    '___class' => 'lang_values',
  ),
  1 => 
  array (
    'created' => 1539790314249,
    'lang_id' => '0E5BD427-7883-903C-FFDD-2309E2D79800',
    'listorder' => 1,
    'ownerId' => NULL,
    'word' => 'mother',
    'updated' => 1539878675079,
    'objectId' => '13518375-E50B-91F7-FFFF-AC72CF60FA00',
    'translate' => 'Мать',
    '___class' => 'lang_values',
  ),
),
 ),
 1 => 
 array (
'code' => 'es',
'created' => 1539801591893,
'name' => 'Español',
'ownerId' => NULL,
'updated' => 1539859937333,
'objectId' => '28106D56-CCD4-557D-FF8F-58D48189F000',
'___class' => 'langs',
'property' => 
array (
  2 => 
  array (
    'created' => 1539801850966,
    'lang_id' => '28106D56-CCD4-557D-FF8F-58D48189F000',
    'listorder' => 1,
    'ownerId' => NULL,
    'word' => 'man',
    'updated' => 1539878651249,
    'objectId' => '17BFA8F1-2E97-79BE-FF56-6556F997C300',
    'translate' => 'Un hombre',
    '___class' => 'lang_values',
  ),
),
),
2 => 
array (
'code' => 'de',
'created' => 1539766491804,
'name' => 'Deutsch',
'ownerId' => NULL,
'updated' => 1539859935404,
'objectId' => '79F70774-58BB-7D1C-FF4A-783DABF25C00',
'___class' => 'langs',
'property' => 
array (
  4 => 
  array (
    'created' => 1539766435042,
    'lang_id' => '79F70774-58BB-7D1C-FF4A-783DABF25C00',
    'listorder' => 1,
    'ownerId' => NULL,
    'word' => 'man',
    'updated' => 1539878692087,
    'objectId' => '6F728A08-0038-6763-FFB6-E87B96075500',
    'translate' => 'ein Mann',
    '___class' => 'lang_values',
  ),
),
),
3 => 
array (
'code' => 'en',
'created' => 1539801538374,
'name' => 'English',
'ownerId' => NULL,
'updated' => 1539859936392,
'objectId' => 'B7B0995E-8BCF-B2AA-FF92-CAB4B7DD4E00',
'___class' => 'langs',
'property' => 
array (
  3 => 
  array (
    'created' => 1539801786691,
    'lang_id' => 'B7B0995E-8BCF-B2AA-FF92-CAB4B7DD4E00',
    'listorder' => 1,
    'ownerId' => NULL,
    'word' => 'man',
    'updated' => 1539878701290,
    'objectId' => '6D6B991A-FCC3-4C32-FFA5-0F3ACA54D400',
    'translate' => 'Man',
    '___class' => 'lang_values',
  ),
    ),
  ),
)
Answer 1
<?php
$array = array(
    0 => array (
        'code' => 'ru',
        'created' => 1539766312218,
        'name' => 'Русский',
        'ownerId' => NULL,
        'updated' => 1539859934434,
        'objectId' => '0E5BD427-7883-903C-FFDD-2309E2D79800',
        '___class' => 'langs',
        'property' => 
        array (
          0 => 
              array (
                'created' => 1539766406514,
                'lang_id' => '0E5BD427-7883-903C-FFDD-2309E2D79800',
                'listorder' => 1,
                'ownerId' => NULL,
                'word' => 'man',
                'updated' => 1539878678826,
                'objectId' => '08F5A487-7649-BB93-FFC0-83C4F37BB500',
                'translate' => 'Человек',
                '___class' => 'lang_values',
              ),
          1 => 
              array (
                'created' => 1539790314249,
                'lang_id' => '0E5BD427-7883-903C-FFDD-2309E2D79800',
                'listorder' => 1,
                'ownerId' => NULL,
                'word' => 'mother',
                'updated' => 1539878675079,
                'objectId' => '13518375-E50B-91F7-FFFF-AC72CF60FA00',
                'translate' => 'Мать',
                '___class' => 'lang_values',
              )
            ),
        ),
    1 => array (
            'code' => 'es',
            'created' => 1539801591893,
            'name' => 'Español',
            'ownerId' => NULL,
            'updated' => 1539859937333,
            'objectId' => '28106D56-CCD4-557D-FF8F-58D48189F000',
            '___class' => 'langs',
            'property' => 
            array (
              2 => 
              array (
                'created' => 1539801850966,
                'lang_id' => '28106D56-CCD4-557D-FF8F-58D48189F000',
                'listorder' => 1,
                'ownerId' => NULL,
                'word' => 'man',
                'updated' => 1539878651249,
                'objectId' => '17BFA8F1-2E97-79BE-FF56-6556F997C300',
                'translate' => 'Un hombre',
                '___class' => 'lang_values',
              ),
            ),
        ),
    2 => array (
        'code' => 'de',
        'created' => 1539766491804,
        'name' => 'Deutsch',
        'ownerId' => NULL,
        'updated' => 1539859935404,
        'objectId' => '79F70774-58BB-7D1C-FF4A-783DABF25C00',
        '___class' => 'langs',
        'property' => array (
          4 => array (
            'created' => 1539766435042,
            'lang_id' => '79F70774-58BB-7D1C-FF4A-783DABF25C00',
            'listorder' => 1,
            'ownerId' => NULL,
            'word' => 'man',
            'updated' => 1539878692087,
            'objectId' => '6F728A08-0038-6763-FFB6-E87B96075500',
            'translate' => 'ein Mann',
            '___class' => 'lang_values',
          ),
        ),
    ),
    3 => array (
        'code' => 'en',
        'created' => 1539801538374,
        'name' => 'English',
        'ownerId' => NULL,
        'updated' => 1539859936392,
        'objectId' => 'B7B0995E-8BCF-B2AA-FF92-CAB4B7DD4E00',
        '___class' => 'langs',
        'property' => array (
          3 => 
          array (
            'created' => 1539801786691,
            'lang_id' => 'B7B0995E-8BCF-B2AA-FF92-CAB4B7DD4E00',
            'listorder' => 1,
            'ownerId' => NULL,
            'word' => 'man',
            'updated' => 1539878701290,
            'objectId' => '6D6B991A-FCC3-4C32-FFA5-0F3ACA54D400',
            'translate' => 'Man',
            '___class' => 'lang_values',
          ),
        ),
    ),
);
$words = array();
foreach ($array as $lang){
    if(!empty($lang['property'])){
        //var_dump($lang['property']);
        foreach($lang['property'] as $word){
            //var_dump($word['word']);
            $words[$word['word']][$lang['code']] = $word['translate'];
        }
    } 
}
foreach($words as $word=>$translate){
    echo "{$word}";
    foreach($array as $lang){
        if(isset($translate[$lang['code']])){
            echo "|{$lang['code']} => {$translate[$lang['code']]}|";
        } else {
            echo "|{$lang['code']} => |";
        }
    }
    echo "\n";
}
//var_dump($words);

ВЫВОД:

man|ru => Человек||es => Un hombre||de => ein Mann||en => Man|
mother|ru => Мать||es => ||de => ||en => |

Online редактор для теста ссылка

READ ALSO
Символы в тексте мешают валидации

Символы в тексте мешают валидации

При генерации xml, иногда в него попадает информация, которая содержит какие-то html-картинки (скрин), и по итогу - ошибка при валидации xml

162
Локализация даты и времени yii2

Локализация даты и времени yii2

используя gridview необходимо выводить дату и время

135
Как задать объекту класса свойства?

Как задать объекту класса свойства?

Имеется класс с тремя свойствами: цвет, тип, модельКаким образом задать эти свойства (с помощью функции?), чтобы при выводе на экран команды...

202
InterBase 7.5 + php

InterBase 7.5 + php

Всем доброго дняУ меня есть база на InterBase 7

162