How can I loop through an array with a custom key:
$sql = "Select * from Users";
$result = mysql_query($sql, $db);
$rows = array();
while($list = mysql_fetch_assoc($result)) {
$rows['customKey'] = array(0, 1, 2, 3);
$rows[] = $list;
}
Then I pass this to another array
foreach($rows as $row) {
$array = array (
'test' => $row,
'test2' => $row['userName']
)
}
Then I print $array
print_r($array['test']);
returns
Array ( [id] => 1 [userName] => John Smith )
why is it not getting $rows['customKey'] here.
Note: I know i need to stop using mysql_* .. this is a legacy application.