0

I want to get 112 position [01] and use this position[01] to compare something ? Can i do that ? Sorry about stupid question. I'm just a new guy really want to known. Thank for any help.

enter image description here

<?
$sql "SELECT * FROM truck WHERE t_ID = '001'";
$arry = odbc_fetch_array($DataExec);           
echo "MAX value position's".$arry;
?>

echo $arry. This 1 i want to show [ MAX value position's 01.]. Or someone have better way.

T2terBKK
  • 319
  • 5
  • 12
  • You can get it with a php function, but since you're working with SQL... You should know those results are returned from the database in a non-meaningful order. – JAL Sep 26 '13 at 05:18
  • 1
    Order them and get the result out from SQL itself if possible – Devesh Sep 26 '13 at 05:19
  • I have no idea what you're trying to do here; what's in your array and what comes out of the query? – Ja͢ck Sep 26 '13 at 05:53
  • MY teacher order "You have to use SQL and put data into array, then find 'Where max value' and show that position in array. All of these must use PHP. – T2terBKK Sep 26 '13 at 06:13
  • Your suggestion to get result by SQL is not match my question. But. thank for any comment. – T2terBKK Sep 26 '13 at 06:14

3 Answers3

3
<?php
$arr_numeric= array('41', '112', '25','54');

$max_position = array_search(max($arr_numeric), $arr_numeric);

echo $max_position;

?>

position start from 0.

OUTPUT

1

liyakat
  • 11,825
  • 2
  • 40
  • 46
1

I get it with a google search.

$maxs = array_keys($array, max($array))

Note: this way you can retrieve every key related to a given max value.

If you are interested only in one key among all simply use $maxs[0]

Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
Satheesh
  • 399
  • 2
  • 5
  • 11
1
$arr =  array('41', '112', '25','54');

$index = array_search(max($arr),$arr);

echo "MAX value position's".$index; 

Similar Question here

Community
  • 1
  • 1
Moeed Farooqui
  • 3,604
  • 1
  • 18
  • 23