|
Posted by J.O. Aho on 10/10/58 11:52
Mr Smith wrote:
> I have a multidim array (only 2 columns) that I need to search in the
> first column for a particular value (there are no duplicate values,
> all are unique).
>
> When it finds it, I need it to return the value held in the 2nd
> column.
function return2ndcol($array,$value) {
for($i=0;$i<count($array);$i++) {
if($value=$array[$i][0]) {
return $array[$i][1];
}
}
return false;
}
$second_column=return2ndcol($the_multi_dim_array,$first_column_value);
false is returned if there is no such value that you wanted to search for,
this will work fine as long as you don't return the value 0, as in an
if-statement 0 == false.
//Aho
Navigation:
[Reply to this message]
|