简体   繁体   中英

php adding columns to a table

I've got the function:

<?php
function calculatepoints($position) {
    $points = array (25, 18, 15, 12, 10, 8, 6, 4, 2, 1);
    if ( $position > count($points) ) { return 0; }
    else { return $points[$position-1]; }
}
?>

and would like to add a points column to my table. I've tried using:

<td><?php echo $points; ?></td>

but kept getting the error: "Undefined variable: points in ..."

Could someone please let me know what it is that I'm doing wrong?

It is because $points is in function's scope, yet you're trying to access it on global scope.

Do: <?php echo calculatePoints($position) ?>

Try:

<?php echo calculatepoints($position); ?>

You should read up on PHP variable scope .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM