hi all,
i tried to call an array like this :
$array = array(3,4);
echo $tt= array_sum($array);
but it showes an error like bellow :
Fatal error: Call to unsupported or undefined function array_sum()
any body here to help me
hi all,
i tried to call an array like this :
$array = array(3,4);
echo $tt= array_sum($array);
but it showes an error like bellow :
Fatal error: Call to unsupported or undefined function array_sum()
any body here to help me
first confirm you are running a PHP version that supports the function, according to the manual it was added in v4.04
I did a quick test and its work with the current v4.1.0 builds
What version of PHP are you using? array_sum() is not supported in versions earlier than 4.0.4.
-geoff
thanks for the information. Actually i'm working on php 3 versions.
Well, that'd explain it The second line (right below the function name) of every function reference in the manual tells you what versions the function is supported in.
-geoff
Since php 3.0 doesn't support array_sum(), you'll have to upgrade to newer version or write array_sum() yourself.
function my_array_sum($array)
{
$sum=0;
for($i=0; $i<count($array); $i++)
if(ctype_digit($array[$i]))
$sum+=$array[$i];
else
return -1;
}
Di
thanks but still have the follwing error with my code ...
$tsel=("select AcctSessionTime from new_acct");
$tssel=mysql_query($tsel) or die("Failed to perform the action.");
while ($trow=mysql_fetch_array($tssel))
{
$mhr=$trow["AcctSessionTime"];
function my_array_sum($mhr)
{
$sum=0;
for($i=0; $i<count($array); $i++)
if(ctype_digit($array[$i]))
$sum+=$array[$i];
else
return -1;
}
}
please tell me where is the problem.
sayma
The problem is that you don't know how to implement functions.
You do not declare a function inside a while loop. Plus, why do you need array_sum()???
Seems to me that you code, could be rewritten as
$sum=0;
while ($trow=mysql_fetch_array($tssel))
$sum+=$trow["AcctSessionTime"];
You don't need array_sum to be used within while loop because you are fetching only one value at a time... So if you pass one value as an array -> that's incorrect, because if array contains only one value, then the sum would be that one value.
Di