Вот пример одного из способов сделать это.Я изменил вашу структуру данных, чтобы ее было проще использовать.Сначала я был сбит с толку, потому что вы не упомянули способ хранения данных.Так что это хорошо только для просмотра одной страницы.
<?php
// initialize data
/**
* Data structure can make the job easy or hard...
*
* This is doable with array_search() and array_column(),
* but your indexes might get all wonky.
*/
$current_asset = [
['name'=>'Land','id'=>1],
['name'=>'Building' ,'id'=>2],
['name'=>'Machinery','id'=>3],
];
/**
* Could use the key as the ID. Note that it is being
* assigned as a string to make it associative.
*/
$current_asset = [
'1'=>'Land',
'2'=>'Building',
'3'=>'Machinery',
];
/**
* If you have more information, you could include it
* as an array. I am using this setup.
*/
$current_asset = [
'1'=> ['name' => 'Land', 'checked'=>false],
'2'=> ['name' => 'Building', 'checked'=>false],
'3'=> ['name' => 'Machinery', 'checked'=>false],
];
// test for post submission, set checked as appropriate
if(array_key_exists('current_asset', $_POST)) {
foreach($_POST['current_asset'] as $key => $value) {
if(array_key_exists($key,$current_asset)) {
$current_asset[$key]['checked'] = true;
}
}
}
// begin HTML output
?>
<html>
<head>
<title></title>
</head>
<body>
<!-- content .... -->
<form method="post">
<?php foreach($current_asset as $key=>$value): ?>
<?php $checked = $value['checked'] ? ' checked' : ''; ?>
<label>
<input type="checkbox" name="current_asset[<?= $key ?>]" value="<?= $key ?>"<?= $checked ?>>
<?= htmlentities($value['name']) ?>
</label>
<?php endforeach; ?>
</form>
<body>
</html>