не получается написать правильно цикл foreach для отображения данных

124
02 августа 2019, 00:20

массив

[
   [
    "Tee",
    "Teenage Mutant Ninja Turtles",
    "Teen Titans",
    "Teenage pregnancy",
    "Teenage Mutant Ninja Turtles (1987 TV series)"
  ],
  [
    "A tee is a stand used to support a stationary ball so that the player can strike it, particularly in golf, tee ball, American football, and rugby.",
    "The Teenage Mutant Ninja Turtles (often shortened to TMNT or Ninja Turtles) are four fictional teenaged anthropomorphic turtles named after Italian artists of the Renaissance.",
    "The Teen Titans, also known as the New Teen Titans or simply the Titans, are a fictional superhero team appearing in American comic books published by DC Comics, often in an eponymous monthly series.",
    "Teenage pregnancy, also known as adolescent pregnancy, is pregnancy in a female under the age of 20. Pregnancy can occur with sexual intercourse after the start of ovulation, which can be before the first menstrual period (menarche) but usually occurs after the onset of periods.",
    "Teenage Mutant Ninja Turtles (initially known as Teenage Mutant Hero Turtles in some European countries due to controversy at the time, and retroactively also known as TMNT 1987 or just TMNT '87) is an American animated television series produced by the studio Murakami-Wolf-Swenson and the French company IDDH."
  ],
  [
     "https://en.wikipedia.org/wiki/Tee",
    "https://en.wikipedia.org/wiki/Teenage_Mutant_Ninja_Turtles",
    "https://en.wikipedia.org/wiki/Teen_Titans",
    "https://en.wikipedia.org/wiki/Teenage_pregnancy",
    "https://en.wikipedia.org/wiki/Teenage_Mutant_Ninja_Turtles_(1987_TV_series)"
  ]
]

нужно получить вот такой массив с объектами

[
     {
     "title": "Tee",
      "description": "A tee is a stand used to support a stationary ball so 
     that the player can strike it, particularly in golf, tee ball, American 
       football, and rugby.",
      "link": "https://en.wikipedia.org/wiki/Tee"
    },
 ]
Answer 1

Как вариант можно сделать вот так:

        $arr = [
        [
            "Tee",
            "Teenage Mutant Ninja Turtles",
            "Teen Titans",
            "Teenage pregnancy",
            "Teenage Mutant Ninja Turtles (1987 TV series)"
        ],
        [
            "A tee is a stand used to support a stationary ball so that the player can strike it, particularly in golf, tee ball, American football, and rugby.",
            "The Teenage Mutant Ninja Turtles (often shortened to TMNT or Ninja Turtles) are four fictional teenaged anthropomorphic turtles named after Italian artists of the Renaissance.",
            "The Teen Titans, also known as the New Teen Titans or simply the Titans, are a fictional superhero team appearing in American comic books published by DC Comics, often in an eponymous monthly series.",
            "Teenage pregnancy, also known as adolescent pregnancy, is pregnancy in a female under the age of 20. Pregnancy can occur with sexual intercourse after the start of ovulation, which can be before the first menstrual period (menarche) but usually occurs after the onset of periods.",
            "Teenage Mutant Ninja Turtles (initially known as Teenage Mutant Hero Turtles in some European countries due to controversy at the time, and retroactively also known as TMNT 1987 or just TMNT '87) is an American animated television series produced by the studio Murakami-Wolf-Swenson and the French company IDDH."
        ],
        [
            "https://en.wikipedia.org/wiki/Tee",
            "https://en.wikipedia.org/wiki/Teenage_Mutant_Ninja_Turtles",
            "https://en.wikipedia.org/wiki/Teen_Titans",
            "https://en.wikipedia.org/wiki/Teenage_pregnancy",
            "https://en.wikipedia.org/wiki/Teenage_Mutant_Ninja_Turtles_(1987_TV_series)"
        ]
    ];
    $keysMapping = [
        0 => 'title',
        1 => 'description',
        2 => 'link'
    ];
    $result = [];
    for ($i = 0; $i < count($arr); $i++) {
        foreach ($arr[$i] as $id => $data) {
            $result[$id][$keysMapping[$i]] = $data;
        }
    }
READ ALSO
Laravel Выбор таблицы при авторизации

Laravel Выбор таблицы при авторизации

При авторизации нужно обратится именно в ту таблицу которая была выбрана при входе

122
загрузка видео на хостинг

загрузка видео на хостинг

Почему картинки загружает нормального размера и видео по 8 байтов?

108
вывест на страницу одни значения, без ключа

вывест на страницу одни значения, без ключа

использую phpmorphy такой код:

121