Scenario: Dynamic navigation based on a custom access control list I'm doing for a project.
I have a table that has all the sections of the website, along with an enum column (yes,no) on whether that user has access to the section. Then I build navigation based off the results. I've been storing the results in an array like so:
$columnValues = array();
while ($row = mysql_fetch_array($result)) {
$columnValues[col1] = $row['col1'];
$columnValues[col2] = $row['col2'];
$columnValues[col3] = $row['col3'];
$columnValues[col4] = $row['col4'];
$columnValues[col5] = $row['col5'];
$columnValues[col6] = $row['col6'];
}
foreach ($columnValues as $key => $val) {
if ($val == "yes") {
$acceptable_pages[] = $key;
}
}
and that works. What I want to do is make that array populate dynamically without hard coding the column names and values.
So this is what I've come up with so far:
while ($row = mysql_fetch_array($result)) {
foreach ($row as $key => $val) {
if ($val == "yes") {
$acceptable_pages[$key]=$val;
}
}
}
The output:
Array ( [0] => yes [col1] => yes [1] => yes [col2] => yes [2] => yes [col3] => yes [3] => yes [col4] => yes [4] => yes [col5] => yes [5] => yes [col6] => yes )
The navigation builds links for the numbers, and the column names.
Admittedly I am not a pro with arrays, so any help would be much appreciated.
EDITED: for clarity