ted_chou12 Posted December 26, 2006 Share Posted December 26, 2006 <?php$arrays = array('05' => 'Ted', '02' => 'A', '04' => 'B',);foreach ($arrays as $number => $name)echo(max($arrays));?>the above code does not work but give you an idea, what i want is the name with the most number...thanksif you dont understand please just reply to thisTed Link to comment https://forums.phpfreaks.com/topic/31843-solved-max-function-and-array/ Share on other sites More sharing options...
.josh Posted December 26, 2006 Share Posted December 26, 2006 so...was the answer given to you in your query thread not good enough? Link to comment https://forums.phpfreaks.com/topic/31843-solved-max-function-and-array/#findComment-147714 Share on other sites More sharing options...
ted_chou12 Posted December 26, 2006 Author Share Posted December 26, 2006 this is different... :( is array, not mysql table... Link to comment https://forums.phpfreaks.com/topic/31843-solved-max-function-and-array/#findComment-147727 Share on other sites More sharing options...
.josh Posted December 26, 2006 Share Posted December 26, 2006 but aren't you asking the same question? Using the same data from the same table? Only difference I'm seeing is that you are asking how to do it with php instead of sql. Does that about sum it up? Because if so, then stick with the sql version; that's what it was designed for. Link to comment https://forums.phpfreaks.com/topic/31843-solved-max-function-and-array/#findComment-147738 Share on other sites More sharing options...
ted_chou12 Posted December 26, 2006 Author Share Posted December 26, 2006 sticky of sql version? Link to comment https://forums.phpfreaks.com/topic/31843-solved-max-function-and-array/#findComment-147743 Share on other sites More sharing options...
emehrkay Posted December 26, 2006 Share Posted December 26, 2006 your keys are strings Link to comment https://forums.phpfreaks.com/topic/31843-solved-max-function-and-array/#findComment-147755 Share on other sites More sharing options...
btherl Posted December 26, 2006 Share Posted December 26, 2006 [code=php:0]<?php$arrays = array('05' => 'Ted', '02' => 'A', '04' => 'B',);$max = '0'; # Must be less than all numbersforeach ($arrays as $number => $name) { $max = max($max, $number);}echo "Maximum is number $max with value {$arrays[$max]}\n";?>[/code] Link to comment https://forums.phpfreaks.com/topic/31843-solved-max-function-and-array/#findComment-147783 Share on other sites More sharing options...
ted_chou12 Posted December 26, 2006 Author Share Posted December 26, 2006 thanks again Link to comment https://forums.phpfreaks.com/topic/31843-solved-max-function-and-array/#findComment-147787 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.