JMair Posted August 28, 2009 Share Posted August 28, 2009 I'm not even sure i have the name correct, but I think it's called the array key. $array[1] I'm referring to the 1. (Array key?) Anyhow. I have an array with each key named, and a variable assigned to each key of course. . I would like to print just the array key in an echo line and I'm not sure where to look. Quote Link to comment https://forums.phpfreaks.com/topic/172323-solved-print-array-key/ Share on other sites More sharing options...
Alex Posted August 28, 2009 Share Posted August 28, 2009 Like this? $arr = Array( 'key1' => 'value', 'key2' => 'value'); echo implode(', ', array_keys($arr)); Output: key1, key2 Edit: That's easier, lol. Quote Link to comment https://forums.phpfreaks.com/topic/172323-solved-print-array-key/#findComment-908575 Share on other sites More sharing options...
JMair Posted August 28, 2009 Author Share Posted August 28, 2009 That is great! However I need to return on Key and not all. I've been tinkering around with it but can't seam to get it to echo 1 key. $todo = array( "9AM" => "Wake Up.", "10AM" => "Drink make hot tea.", "11AM" => "Finish reading CNET news.", ); So if I wanted to just echo a the Key value to Wake Up. I'm not sure how to do it. Quote Link to comment https://forums.phpfreaks.com/topic/172323-solved-print-array-key/#findComment-908611 Share on other sites More sharing options...
lemmin Posted August 28, 2009 Share Posted August 28, 2009 It really depends on how you are using the array. You might be looking for the array_search() function: http://us2.php.net/manual/en/function.array-search.php Quote Link to comment https://forums.phpfreaks.com/topic/172323-solved-print-array-key/#findComment-908616 Share on other sites More sharing options...
Alex Posted August 28, 2009 Share Posted August 28, 2009 That is great! However I need to return on Key and not all. I've been tinkering around with it but can't seam to get it to echo 1 key. $todo = array( "9AM" => "Wake Up.", "10AM" => "Drink make hot tea.", "11AM" => "Finish reading CNET news.", ); So if I wanted to just echo a the Key value to Wake Up. I'm not sure how to do it. edit: nvm, use array_search() Quote Link to comment https://forums.phpfreaks.com/topic/172323-solved-print-array-key/#findComment-908626 Share on other sites More sharing options...
JMair Posted August 28, 2009 Author Share Posted August 28, 2009 thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/172323-solved-print-array-key/#findComment-908644 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.