0

I d like to access the PHP variable static $linecount in the function zaehler:

if ($zaehler < $linecount)  {
        zaehler ();

I was trying global $linecount and static $linecount, but i get an error message. Could you help me? I am a beginner.

<?php

$file=$textfile;
static $linecount = 0;
$handle = fopen($file, "r");
while(!feof($handle)){
    $line = fgets($handle);
    $linecount++;
}
fclose($handle);
echo $linecount;

function zaehler()
{
    static $zaehler = 0;
    $zaehler++;
    echo $zaehler;
    if ($zaehler < $linecount )  {
        zaehler ();
    }
    $zaehler--;
}
?>
jasinth premkumar
  • 1,430
  • 1
  • 12
  • 22
Yvar
  • 155
  • 4
  • 14
  • where do you call the function `zaehler()`? Best would be to pass in `$linecount`: `zaehler($linecount)` – Jeff Dec 16 '17 at 14:52
  • but to answer your question: you would have to write `global $linecount;` in the beginning of function `zaehler()`. Use of globals is disencouraged though – Jeff Dec 16 '17 at 14:55
  • @Jeff Thanks for your answer. – Yvar Dec 16 '17 at 16:11

0 Answers0