Hey, I need to create something like that: I have a group of numbers like 1 - 2 1 - 6 1 - 34 1 - 4 2 - 5 2 - 7 2 - 11 2 - 43 what I need to do is to match second column to find out first column number lets say I have 43 - script have to find that 43 belongs to 2 , its very easy to do with mysql, but this part have to be done only in php probably with array any ideas ? thanks in advance
If you want to do this with array, show us the array structure? Like this below? $array[1] = array(2,6,34,4); $array[2] = array(5,7,11,43); PHP:
I suppose that numbers in second column are unique, so there is no situation when 43 belongs to 1 and 2. In that case make an array like that: $numbers = array( 2 => 1, 6 => 1, 34 => 1, 4 => 1, 5 => 2, 7 => 2, 11 => 2, 43 => 2); $result = array[43]; PHP:
Or if they're not unique, which is most likely; $numbers = array( 1 => 2, 1 => 6, 1 => 34, 1 => 4, 2 => 5, 2 => 7, 2 => 11, 2 => 43); $key = array_search('43', $numbers) PHP:
So the main problem now is to make such an array. deriklogov, tell us how are these numbers stored? Plain text, xml, database or what?
@AsHinE, your code should be : $numbers = array( 2 => 1, 6 => 1, 34 => 1, 4 => 1, 5 => 2, 7 => 2, 11 => 2, 43 => 2); $result = $numbers[43]; PHP: @Sky AK47, the key is duplicated.
Thank you very much guys, code working like a charm. $numbers = array( 2 => 1, 6 => 1, 34 => 1, 4 => 1, 5 => 2, 7 => 2, 11 => 2, 43 => 2); $result = $numbers[43]; Problem solved THANK YOU