RE: [PHP] Retrieving array_keys from $_POST
| From: | Ernest E Vogelsinger | Date: | Fri, 23 May 2003 07:52:23 +0000 |
| Subject: | RE: [PHP] Retrieving array_keys from $_POST | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148727@lists.php.net to get a copy of this message | ||
At 02:40 23.05.2003, John W. Holmes said:
--------------------[snip]--------------------
>Well, not quite. Remember, array_keys() returns another array, so you
>have to loop through it:
>
>$keys = array_keys($_POST);
>foreach($keys as $key)
>{ echo "Key: $key<br />"; }
>
>of course, you could always do the same thing with just $_POST
>
>foeach($_POST as $key=>$value)
>{ echo "Key: $key<br />Value of $key: $value<br />"; }
--------------------[snip]--------------------
You can bring the join() function to convenient use here... for example, to
generate a nicely formatted ASCII table of any arbitrary array, you could
echo '<table><tr><th>', join('</th><th>',
array_keys($array), '</th></tr>';
foreach ($array as $line)
echo '<tr><td>', join('</td><td>', $line),
'</td></tr>';
echo '</table>';
Quick and elegant...
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/