cannot redeclare
Von: dragonet (dennistogliquesto.pavesi@fastwebnet.it) [Profil]
Datum: 03.05.2008 20:40
Message-ID: <L3ZSj.30148$o06.12212@tornado.fastwebnet.it>
Newsgroup: it.comp.www.php
Datum: 03.05.2008 20:40
Message-ID: <L3ZSj.30148$o06.12212@tornado.fastwebnet.it>
Newsgroup: it.comp.www.php
Ciao a tutti, ho iniziato da poco a studiare php e avrei bisogno di un
aiuto. Sto scrivendo questo piccolo script che trova il valore massimo tra
quelli presenti in un array:
<?php
function max($array,$dimensione)
{
$i;
$highest;
$highest=$array[0];
for($i=0;$i<$dimensione;$i++)
{
if($array[$i]>$highest)
{$highest=$array[$i];}
}
return $highest;
}
?>
<html>
<title>maggiore</title>
<body>
<br><br>
<H3>questo script trova il valore più alto tra quelli contenuti in un
array</H3>
<br><br>
<H3>i valori dell'array sono: 10,50,35,2,75,40,1,62,8,9</H3>
<?php
$vettore[10]=array(10,50,35,2,75,40,1,62,8,9);
$i;
$massimo=0;
$massimo=max($vettore,$10);
print("<br><br>il valore massimo e': $massimo");
?>
Quando lo lancio (in un server web apache, utilizzo xampp per Linux) mi
compare l'errore:
Fatal error: Cannot redeclare max()
in /opt/lampp/htdocs/xampp/valore_massimo.php on line 20
Non mi pare proprio che la funzione sia dichiarata più di una volta.
Qualcuno può spiegarmi? Un'altra domanda: anche nella chiamata alla
funzione devo usare la '$'? Anche per la dimensione? Un array va passato ad
una funzione con nome e dimensione (come nel linguaggio C)? Grazie in
anticipo.
DENNIS
[ Auf dieses Posting antworten ]Antworten
- Filippo Toso - Creative Park (03.05.2008 14:51)
- Filippo Toso - Creative Park (03.05.2008 14:54)
- Alessandro Cara (03.05.2008 19:19)
