Heyo,
I need to be able to get the ASSOC key name of an element in an array that has both ASSOC and INTEGER indices. Basically, I need to display this in my output:
$[keyName] : $[corresponding value]
with actual data:
SSN: 111111111
At first, I didn't even know what function to try, and I read up and tried many. I'm not certain, but I think array_keys() will get what I want (and I can even add the search parm), but its output isn't exactly in a format that's ready to be used without a lot of string manipulation (stripping out everything but the ASSOC key name that is all I really want). It just seems to me that there's gotta be an easier way...
The output is being formatted in HTML as follows:
...
$fields = mysql_num_fields($rawResult);
print ("<table border=\"1\">\n");
printf ("Fields returned: %s", $fields);
while ($array = mysql_fetch_array($rawResult, MYSQL_BOTH))
{
for ($tr=0,$cell=0; ($tr <= 3 && $cell <= $fields); $tr++)
{
print (" <tr>\n");
printf (" <td>%s: %s</td>\n", array_keys($array, $array[$cell]),$array[$cell]);
$cell++;
printf (" <td>%s: %s</td>\n", array_keys($array, $array[$cell]),$array[$cell]);
$cell++;
printf (" <td>%s: %s</td>\n", array_keys($array, $array[$cell]),$array[$cell]);
$cell++;
print (" </tr>\n");
$tr=0;
}
}
print ("</table>\n");
...
BTW: I realize that the above code won't work (without said string manipulation of the array_keys output and probably some use of reset on the array). The use of array_keys() above is just a placeholder for whatever it is that I should REALLY be using to get the index names... If there is some other way... 😕
This is actually only temporary, until I build a table storing verbose synonyms for the ASSOC names that would actually get returned in the HTML. (for example, the "SSN" would/might equate to and be presented as "Social Security Number" after I get that part working...) For now, just some simple field names to go with the data would really be nice (and doing so without hard-coding the field names in the PHP, and then be subject to maintenance later would be best).