Jump to content

Function min-max problem


quelle

Recommended Posts

Im working on 2 functions which will check lowest and biggest value in array. So this code works fine, but only problem it isnt function

<?php 
$brojevi = array(25, 14, 62);
    $mxm = $brojevi[0];

    for ($i=0; $i < count($brojevi); $i++) {
    if($brojevi[$i]>$mxm) {
    $mxm = $brojevi[$i];
    	}
    }
    echo $mxm;

/////////////////////////////////////////////////////

	$brojevi = array(25, 14, 62);
    $mnm = $brojevi[0];

    for ($i=0; $i < count($brojevi); $i++) {
    if($brojevi[$i]<$mnm) {
    $mnm = $brojevi[$i];
    	}
    }
    echo $mnm;

?>

And now code which doesnt work - the functions part

<?php
////////////////////////////////////////////////////
function max($niz)
{
	$mxm = $niz[0];

	for ($i=0; $i < count($niz); $i++) {
    	if($niz[$i]>$mxm) {
    	$mxm = $niz[$i];
    		}
    	}
    return $mxm;
}
////////////////////////////////////////////////////
function min($niz){
	$mnm = $niz[0];

	for ($i=0; $i < count($niz); $i++) {
    	if($niz[$i]>$mnm) {
    	$mnm = $niz[$i];
    		}
    	}
    return $mnm;
};
////////////////////////////////////////////////////

$jabuke = array(15, 25, 559, 554);
$kruske = array(12, 9, 2, 44);

max($jabuke);
min($kruske);

?>

I need this badly tommorow :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.