JREAM Posted December 12, 2009 Share Posted December 12, 2009 I have this: $arrForms['title'] I want like to get: title Basically so I can check a field, and also the output will tell me the name of the array piece. Link to comment https://forums.phpfreaks.com/topic/184848-how-to-get-array-key-when-its-a-name/ Share on other sites More sharing options...
rajivgonsalves Posted December 12, 2009 Share Posted December 12, 2009 there are many ways to do this consider this <?php $arrForms['title'] = 'test'; echo key($arrForms); ?> Link to comment https://forums.phpfreaks.com/topic/184848-how-to-get-array-key-when-its-a-name/#findComment-975771 Share on other sites More sharing options...
JREAM Posted December 12, 2009 Author Share Posted December 12, 2009 thank you Link to comment https://forums.phpfreaks.com/topic/184848-how-to-get-array-key-when-its-a-name/#findComment-975774 Share on other sites More sharing options...
Andy-H Posted December 12, 2009 Share Posted December 12, 2009 You could use foreach foreach( $arrForms ad $k => $val ) { // $k = array key... } or you could use array_keys $keys = array_keys($arrForms); reset($keys); while ($key = current($keys)) { // $key = array key... next($key); } Link to comment https://forums.phpfreaks.com/topic/184848-how-to-get-array-key-when-its-a-name/#findComment-975776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.