3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* jobTitle.php Ideally, the model layer is used to access database data More directly generate the desired result array to be returned with loadColumn(): public function getOptions() { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('jobtitle')->from('#__jobs'); return $db->setQuery($query)->loadColumn(); } Ideally, collecting submitted data should be done in the controller layer. Ideally, generating html markup should be done in the view layer. --- technologies.php Use loadResult(): $backend = $db->setQuery($query)->loadResult(); The foreach body can be simplified: foreach ($backend as $line) { $result[] = [$line, in_array($line, $currentBackend)]; } You don't need to increment your own counter. Employ D.R.Y. coding regarding the if block. sprintf() spares interpolation/concatenation. Again, I would rather this mark up be generated in the view layer. $html = '<fieldset id="jform_technologies" class="list checkboxes">'; foreach ($this->getOptions() as $i => [$line, $checked]) { $html .= sprintf( '<label for="%1$s" class="checkbox"> <input type="checkbox" id="%1$s" name="jform[technologies][]" value="%2$s"%3$s>%2$s </label>', 'jform_backend' . $i, $line, $checked ? ' checked' : '' ); } $html .= '</fieldset>'; return $html; */
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 8.0.0 - 8.0.12, 8.1rc1 - rc3

preferences:
36.29 ms | 460 KiB | 5 Q