-2

I have such a loop:

for($i=0;$i<count($dersler);$i++)
{
   echo $dersler[$i].', ';
}

I want to run this loop on another page by capturing $dersler variable from another page. How can I manage it? Thank you.

  • I have tried "global", but it didn't work. – Hasan Sait Arslan Dec 22 '13 at 19:28
  • Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See [Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). – rene Dec 22 '13 at 19:31

2 Answers2

1

You could pass the variable as a query parameter and access it again using the $_GET superglobal. An other option is posting the variable to the page using a form, and accessing it through $_POST.

But the solutions mentioned above require sending the value to the client side where it could be modified. If this is not desired, you could use a session to store a value serverside, between requests from the same client. Take a look at the session documentation: http://www.php.net/manual/en/book.session.php.

P44T
  • 1,109
  • 12
  • 21
0

You can store $dersler in a session.

on the first page :

session_start();
$_SESSION['dersler'] = $dersler;

and on the other page :

session_start();
$desler = $_SESSION['dersler']; 
for($i=0;$i<count($dersler);$i++){
    echo $dersler[$i].', ';
}
gbu
  • 56
  • 5