-1

I've two page , first page there's an array data and second page I want call array data

Like this

First page index.php

    $array_data[]=$array_tmp;
    print_r($array_data); // array can display in this page

    $_SESSION['one'] = $array_data;

Second page next.php I want to call array from first page

session_start();

$array = $_SESSION['one'];
foreach( $array as $key => $value ) {
    echo $value;
}

print_r($_SESSION['one'])

May I know what's wrong? As array can't display in second page.

Rikesh
  • 26,156
  • 14
  • 79
  • 87
TARA
  • 529
  • 1
  • 6
  • 23

2 Answers2

-1

I think you should change this code $array = $_SESSION['one']; to $array[] = $_SESSION['one'];. I`m not sure & not tested as well but I think so. Hope this will help.

Maulik M. Dodia
  • 48
  • 1
  • 1
  • 10
-1

You need to start the session if you already have not. Without starting the session, you can't assign value to the session variable. So the first code snippet would be like this:

session_start();
$array_data[]=$array_tmp;
print_r($array_data); // array can display in this page

$_SESSION['one'] = $array_data;

Second snippet looks fine but the last line is missing a semicolon. It might sound silly, but that can prevent the whole script from running. Here's the code fixed.

session_start();

$array = $_SESSION['one'];
foreach( $array as $key => $value ) {
    echo $value;
}
print_r($_SESSION['one']);

Post more code if this does not work.

Gogol
  • 3,033
  • 4
  • 28
  • 57