Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem searching arrays. Need help understanding

Status
Not open for further replies.

csphard

Programmer
Apr 5, 2002
194
US
Need help. The following is my array
Array ( [1] => 10 [2] => 10 )

I am trying to search this array doing the following

$thisRow = $row[id];
$myQty = array_search($thisRow, $contents);


the answer I am getting is
thisRow = 10
myQty = 1

When I want
thisRow = 1
myQty = 10

What am I getting wrong.

Howard
 
You are setting thisrow to the VALUE of row[id] and to the array key of that value ( which would be just id)
 
I am sorry. I read your answer and I do not understand.
Help. Need more information
 
I'm not sue you are understanding how an array works, or how array_search works.

$row['id'] would return the value of the array for the id key. $row[1] returns 10. row[2] also returns 10. if you had a third value in your array: Array ( [1] => 10 [2] => 10 [3]=> 12)
$row[3] would return 12.


Then you use the array_search which returns a key in the
array that holds the specified value.

So you search the array for the value 10. the first place it finds it is in the 1 key so it returns 1.

If you where to search for 12 it would return 3.










----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top