how to get lowest value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jayipee@gmail.com

    how to get lowest value

    hi to all. can anybody help me figuring out how to get the minimum
    value from this list.

    log1 354
    log2 232
    log3 155

    from the above list i want to have a return value "log3" since this is
    the lowest value in the list.

    I tried to use $test = min(array('log1 ' =354,'log2' =232,'log3' =>
    155));
    but it returns only the value 155 and not log3

    i would be very glad if someone can help me.

  • Rik

    #2
    Re: how to get lowest value

    jayipee@gmail.c om wrote:
    hi to all. can anybody help me figuring out how to get the minimum
    value from this list.
    >
    log1 354
    log2 232
    log3 155
    >
    from the above list i want to have a return value "log3" since this is
    the lowest value in the list.
    >
    I tried to use $test = min(array('log1 ' =354,'log2' =232,'log3' =>
    155));
    but it returns only the value 155 and not log3
    >
    i would be very glad if someone can help me.
    $array = array('log1' =354,'log2' =232,'log3' =155);
    asort($array);
    $min_key = reset(array_key s($array));

    Grtz,
    --
    Rik Wasmus


    Comment

    • Geoff Muldoon

      #3
      Re: how to get lowest value

      luiheidsgoeroe@ hotmail.com says...
      jayipee@gmail.c om wrote:
      hi to all. can anybody help me figuring out how to get the minimum
      value from this list.

      log1 354
      log2 232
      log3 155

      from the above list i want to have a return value "log3" since this is
      the lowest value in the list.

      I tried to use $test = min(array('log1 ' =354,'log2' =232,'log3' =>
      155));
      but it returns only the value 155 and not log3

      i would be very glad if someone can help me.
      >
      $array = array('log1' =354,'log2' =232,'log3' =155);
      asort($array);
      $min_key = reset(array_key s($array));
      or:

      $log_array = array("log1"=>3 54, "log3"=>155 , "log2"=>232 );
      arsort($log_arr ay);
      $log_array = array_flip($log _array);
      echo array_pop($log_ array);

      Geoff M

      Comment

      • Rik

        #4
        Re: how to get lowest value

        Geoff Muldoon wrote:
        luiheidsgoeroe@ hotmail.com says...
        >jayipee@gmail.c om wrote:
        >>hi to all. can anybody help me figuring out how to get the minimum
        >>value from this list.
        >>>
        >>log1 354
        >>log2 232
        >>log3 155
        >>>
        >>from the above list i want to have a return value "log3" since this
        >>is the lowest value in the list.
        >>>
        >>I tried to use $test = min(array('log1 ' =354,'log2' =232,'log3'
        >>=155));
        >>but it returns only the value 155 and not log3
        >>>
        >>i would be very glad if someone can help me.
        >>
        >$array = array('log1' =354,'log2' =232,'log3' =155);
        >asort($array );
        >$min_key = reset(array_key s($array));
        >
        or:
        >
        $log_array = array("log1"=>3 54, "log3"=>155 , "log2"=>232 );
        arsort($log_arr ay);
        $log_array = array_flip($log _array);
        echo array_pop($log_ array);
        In most cases, yes.
        Now try:
        $log_array = array("log1"=>3 54, "log3"=>nul l, "log2"=>232 );

        You can see why I'm a bit reluctant to use values as the keys.

        Grtz,
        --
        Rik Wasmus


        Comment

        • Geoff Berrow

          #5
          Re: how to get lowest value

          Message-ID: <82c52$45358556 $8259c69c$21674 @news2.tudelft. nlfrom Rik
          contained the following:
          >i would be very glad if someone can help me.
          >
          >$array = array('log1' =354,'log2' =232,'log3' =155);
          >asort($array );
          >$min_key = reset(array_key s($array));
          Sounds like a homework question.

          Homeworky answer:

          $array = array('log0'=>2 33,'log1' =354,'log2' =232,'log3' =255);
          $count=1;
          foreach($array as $key=>$value){
          if($count==1 ){
          $low_val =$value;
          $low_key=$key;
          }
          elseif($value<$ low_val){
          $low_val =$value;
          $low_key=$key;
          }
          $count++;
          }
          echo "$low_key =$low_val";

          How to handle null values and duplicates left as an exercise. :-)
          --
          Regards,

          Geoff Berrow

          Comment

          • Kimmo Laine

            #6
            Re: how to get lowest value

            <jayipee@gmail. comwrote in message
            news:1161134572 .618837.75610@m 7g2000cwm.googl egroups.com...
            hi to all. can anybody help me figuring out how to get the minimum
            value from this list.
            >
            log1 354
            log2 232
            log3 155
            >
            from the above list i want to have a return value "log3" since this is
            the lowest value in the list.
            >
            I tried to use $test = min(array('log1 ' =354,'log2' =232,'log3' =>
            155));
            but it returns only the value 155 and not log3

            $array = array('log1' =354,'log2' =232,'log3' =155);
            $test1 = array_search(mi n($array), $array);
            $test2 = array_keys($arr ay, min($array));

            The difference between aray_search and array_keys is that _keys returns an
            array of keys for matching elements. That means if several minimum values
            are found, all matching elements are returned. Array_search just returns the
            first.

            --
            "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
            http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
            spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


            Comment

            Working...