Hello guys I need a little help here about arrays. I have 3 arrays, one is for base the other is for header and the last is the header fields. In my PHP code I have this I am using CodeIgniter.
public function field_study() {
$fields_header = array('Accounting/Finance','Admin/Human Resources','Arts/Media/Communications','Building/Construction','Computer/Information Technology','Education/Training','Engineering','Healthcare','Hotel/Restaurant','Manufacturing','Sales/Marketing','Sciences', 'Services', 'Others');
$fields = array(
array(
'Audit & Taxation',
'Bangking/Financial',
'Corporate Finance/Investment',
'General/Cost Accounting'
),
array(
'Clerical/Administrative',
'Human Resources',
'Secretarial',
'Top Management',
),
array(
'Advertising',
'Arts/Creative Design',
'Entertainment',
'Public Relations'
),
array(
'Architect/Interior Design',
'Civil Engineering/Construction',
'Property/Real Estate',
'Quantity Serveying'
),
array(
'IT - Hardware',
'IT - Network/Sys/DB Administrator',
'IT - Software',
),
array(
'Education',
'Training $ Dev.'
),
array(
'Chemical Engineering',
'Electrical Engineering',
'Electronics Engineering',
'Environmental Engineering',
'Industrial Engineering',
'Mechanical/Automotive Engineering',
'Oil/Gas Engineering',
'Other Engineering'
),
array(
'Doctor/Diagnosis',
'Pharmacy',
'Nurse/Medical Support',
),
array(
'Food/Beverage/Restaurant',
'Hotel/Tourism'
),
array(
'Maintenance',
'Manufacturing',
'Process Design & Control',
'Purchasing/Material Mgmt',
'Quality Assurance'
),
array(
'Sales - Corporate',
'Marketing/Business Dev',
'Merchandising',
'Retail Sales',
'Sales - Eng/Tech/IT',
'Sales - Financial Services',
'Telesales/Telemarketing'
),
array(
'Actuarial/Statistics',
'Agriculture',
'Aviation',
'Biotechnology',
'Chemistry',
'Food Tech/Nutritionist',
'Geology/Geographics',
'Science & Technology'
),
array(
'Security/Armed Forces',
'Customer Service',
'Logistics/Supply Chain',
'Law/Legal Services',
'Personal Care',
'Social Services',
'Tech & Helpdesk Support'
),
array(
'General Work',
'Journalist/Editors',
'Publishing',
'Others'
)
);
$main = array(
$fields_header, $fields
);
return $main;
}
I need to include this in my form. So I have something like this after I hardcoded it.
<select name="academic[1][field_study]" id="field_study" class="form-control">
<option value="" selected="selected">- Select Field Of Study -</option>
<optgroup label="Accounting/Finance">
<option value="Audit & Taxation">Audit & Taxation</option>
<option value="Banking/Financial">Banking/Financial</option>
<option value="Corporate Finance/Investment">Corporate Finance/Investment</option>
<option value="General/Cost Accounting">General/Cost Accounting</option>
</optgroup>
<optgroup label="Admin/Human Resources">
<option value="Clerical/Administrative">Clerical/Administrative</option>
<option value="Human Resources">Human Resources</option>
<option value="Secretarial">Secretarial</option>
<option value="Top Management">Top Management</option>
</optgroup>
But what I want is include this array and use it in a loop but I don't know how. Can you help me with this? Ok that's all thanks.
'Accounting/Finance' => array('Audit & Taxation', etc...)and doforeach($fields AS $key => $val)to get the opt group, thenforeach($val AS $option)to loop through the options for each key?