$_GET['id']))[0]; if (isset($_POST['create'])) { $postData = $_POST; $result = []; foreach ($postData as $key => $value) { if (strpos($key, 'variable') === 0) { preg_match('/_(\d+)$/', $key, $matches); if (isset($matches[1])) { $index = $matches[1]; if (!isset($result[$index])) { $result[$index] = []; } $newKey = preg_replace('/^variable/', '', $key); $newKey = preg_replace('/_\d+$/', '', $newKey); $result[$index][$newKey] = $value; } } } $jsonResult = json_encode($result, JSON_PRETTY_PRINT); DB::query('INSERT INTO entities VALUES (\'0\', :title, :createdate, :sampledata, :color)', array(':title' => $_POST['title'], ':createdate' => time(), ':sampledata' => $jsonResult, ':color' => $_POST['color'])); header('Location: /admin?type=Entities'); } ?>