Jump to content

[SOLVED] array_search for loop question.


JMair

Recommended Posts

<?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?

 

Link to comment
https://forums.phpfreaks.com/topic/172337-solved-array_search-for-loop-question/
Share on other sites

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.

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."

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.