therealwesfoster Posted April 17, 2008 Share Posted April 17, 2008 Here's what I need. Lets say I have an array: $arr = array("a","b","c","d"); I want to be able to do something like: echo array_index_number("c",$arr); It should echo 2 (because $arr[2] is c) Now I know that isn't a real function (or is it? that'd be weird), but thats what I'm trying to do. How would I do this? Thanks Link to comment https://forums.phpfreaks.com/topic/101464-get-an-arrays-index-number/ Share on other sites More sharing options...
marcus Posted April 17, 2008 Share Posted April 17, 2008 Something like? <?php $arr = array("a","b","c","d"); $c = array_keys($arr, "c"); if(count($c) > 1){ echo "<pre>",print_r($c),"</pre>"; }else { echo $c[0]; } ?> Link to comment https://forums.phpfreaks.com/topic/101464-get-an-arrays-index-number/#findComment-519018 Share on other sites More sharing options...
laffin Posted April 17, 2008 Share Posted April 17, 2008 echo array_search("c",$arr); Link to comment https://forums.phpfreaks.com/topic/101464-get-an-arrays-index-number/#findComment-519130 Share on other sites More sharing options...
therealwesfoster Posted April 19, 2008 Author Share Posted April 19, 2008 echo array_search("c",$arr); Thats it exactly. Thanks Link to comment https://forums.phpfreaks.com/topic/101464-get-an-arrays-index-number/#findComment-520901 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.