REX: Counter (REX Vars and Native) Code Example

index.rex :
<?php
// Demonstrates the use of variables in REX - first counter uses the inbuilt REX variables
// then it calls native-counter.rex which uses standard PHP variables to accomplish the same
// thing

$counter = $REX->Get("counter"); // get the REX variable 'counter'
if ($counter == false) $counter=0; // if it doesn't exist (false) set it to 0

if ($counter == 0) echo "Counter using REX variable stack: <BR />\n"; // title

echo $counter . " <BR />\n"; // echo out the counter
$counter++; // increment
$REX->Set("counter",$counter); // save back to the REX variable stack
if ($counter<10) $REX->ExecFile("index.rex"); // until it's 10 re-call the index.rex (this file)
else $REX->ExecFile("native-counter.rex"); // now call the native example
?>

native-counter.rex :
<?php
global $count; // essential as REX is called within a loop
if (!isset($count)) $count=0; // check and set to 0 if required
if ($count==0) echo "<BR />\nNative PHP Variable Counter: <BR />\n"; // title
echo $count." <BR />\n";
$count++;
if ($count<10) $REX->ExecFile("native-counter.rex"); // loop through 0 to 9
?>



REX Code Example - © Copyright 2010 David Cutting, All Rights Reserved Licenced under the GNU General Public Licence Version 3