PHP Programming > Beginners - Learning PHP

printing an array incrementally

<< < (2/2)

cw322:
Yep this works just fine. Thanks so much Smokey PHP! I didn't know how powerful sessions could be. You've saved me hours of searching. Cheers, cw322


--- PHP Code: ---

<?php 
session_start();
 
if(isset($_SESSION['count']))
{
$_SESSION['count']++;
}
else
{
$_SESSION['count'] = 1;
}
 
$page_load_count = $_SESSION['count'];

$full_sequence = array ('in ', 'noua ', 'fert ', 'animus ', 'mutatas ', 'dicere ', 'formas ');

$length = $page_load_count;

$current_sequence = array_slice($full_sequence, 0, $length);

$space_separated_sequence = implode(" ", $current_sequence);

echo $space_separated_sequence;

?>


--- End code ---

Smokey PHP:
Glad to have helped. One note though on the code you posted:


--- PHP Code: ---$page_load_count = $_SESSION['count'];
$length = $page_load_count;
$current_sequence = array_slice($full_sequence, 0, $length);
--- End code ---


As you aren't using $page_load_count other than to set it to $length, can you not just use $page_load_count in array_slice or put $length = $_SESSION['count'] ?  Try to avoid pointless variables! Other than that, looking good.

Navigation

[0] Message Index

[*] Previous page

Go to full version