JMair Posted August 28, 2009 Share Posted August 28, 2009 <?php $todo = array( 1 => "9AM Wake Up.", 2 => "10AM Drink make hot tea.", 3 => "11AM Finish reading CNET news.", 4 => "12AM Shower and get dressed.", 5 => "1PM Finish watering the garden.", 6 => "2PMTake a nap.", 7 => "3PM Dream about something fantastic.", 8 => "4PM Wake up from nap.", 9 => "5PM Go to work.", ); for ($i = 1; $i <= 20 ; $i++) { // notice the 20 in order to see the whole readout of array_search. //echo $i ."<br>"; $key = array_search($i, $todo); echo $key ."<br>"; }//end of for ?> Print out is exactly. 5 6 7 8 9 1 2 3 4 What would be causing this? Quote Link to comment Share on other sites More sharing options...
Alex Posted August 28, 2009 Share Posted August 28, 2009 What are you expecting/trying to get? Quote Link to comment Share on other sites More sharing options...
JMair Posted August 28, 2009 Author Share Posted August 28, 2009 1 2 3 4 5 6 7 8 9 I get that when I do echo $i ."<br>"; I'm just unsure why the following doesn't give it in order and adds additional <br> instead. $key = array_search($i, $todo); echo $key ."<br>"; I'm just trying to understand it is all really. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted August 28, 2009 Share Posted August 28, 2009 Reading the documentation on array_search() may come in handy. It explains why you're getting your results. Quote Link to comment Share on other sites More sharing options...
JMair Posted August 28, 2009 Author Share Posted August 28, 2009 I did before I posted but didnt see anything direct enough for me I suppose. I'll check again. Thanks guys. Also, I have to add, I've learned about as much or more from this forum than I have from my PHP book and a class I took a while ago. Thanks for the help again. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted August 28, 2009 Share Posted August 28, 2009 I did before I posted but didnt see anything direct enough for me I suppose. I'll check again. Thanks guys. Also, I have to add, I've learned about as much or more from this forum than I have from my PHP book and a class I took a while ago. Thanks for the help again. array_search() searches an array's values. The first instance of the value '1' is the 5th element of the array, whose value is "1PM Finish watering the garden." Quote Link to comment 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.