what you are missing, relevant to both my reply above and the reply by @Barand, is a table where the (currently 3) vehicle choices are DEFINED. it is this definition that will allow you to produce the checkbox markup without writing out code for every possible value.
see the following example form processing/form code, related to the method stated in my reply above (there are comments in the code at the point where you would query for and retrieve the existing data to be edited) -
<?php
// you would query to get the following data from whereever it is stored
// assuming that $table in the OP's code is an array of fetched data defining the checkbox choices
$table = [];
// the index is the id
// do you really want the 'I have a' text with every entry? how about just a heading to select the vehicles the user has?
$table[1] = ['name'=>'I have a yacht'];
$table[2] = ['name'=>'I have a super car'];
$table[3] = ['name'=>'I have a plane'];
$post = []; // array to hold a trimmed working copy of the form data
$errors = []; // array to hold user/validation errors
// recursive function to trim data
function _trim($val){
if(is_array($val)){
return array_map('_trim',$val);
} else {
return trim($val);
}
}
// post method form processing code
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
// trim all the data at once
$post = array_map('_trim',$_POST);
// validate the data here, storing validation errors in $errors, using the field name as the array index
// if no errors, use the submitted data
if(empty($errors))
{
// insert new data or update existing data here...
}
}
// get method business logic - get/produce data need to display the dynamic content on the page
// if editing existing saved choices, there would be a get input to validate, then used to query
// for and retrieve the existing choice data, but only if the form has never been submitted ($post
// is empty), storing the fetched data in $post, in a sub-array named 'vehicle', in the same format
// as the form will submit it as.
// html document starts here...
?>
<form method='post'>
<?php
// display the checkboxes, with any existing choices pre-checked
foreach($table as $id=>$arr)
{
$chk = in_array($id,$post['vehicle'] ?? []) ? ' checked' : '';
// note: if you put the <label></label> around the form field, you don't need to generate unique ids to make it work
echo "<label class='boxstyle'><input type='checkbox' name='vehicle[]' value='$id'$chk> {$arr['name']}</label><br>\n";
}
?>
<input type='submit'>
</form>