tags:

views:

82

answers:

3

Hello,

When sending data from a form to a second page, the value of the session is always with the name "Array" insteed of the expected number.

The data should get displayed in a table, but insteed of example 1, 2, 3 , 4 i get : Array, Array, Array. (A 2-Dimensional Table is used)

Is the following code below a proper way to "call" upon the stored values on the 2nd page from the array ?

$test1 = $_SESSION["table"][0];
$test2 = $_SESSION["table"][1];
$test3 = $_SESSION["table"][2];
$test4 = $_SESSION["table"][3];
$test5 = $_SESSION["table"][4];

What exactly is this, and how can i fix this? Is it some sort of override that needs to happen?

Best Regards.

+5  A: 

As noted, try

echo "<pre>";
print_r($_SESSION);
echo "</pre>";

That should show you what's in the session array.

Ian
Everything in the array works just fine.But i cannot get the info to display in my table.I have tried it with the print_r already cheers.
Nerathas
What does the output from the print_r show? That may help us with finding the issue.
Ian
`print_r` is not to put into your page (as stated by jordanstephens in his answer). It's for debugging, so we can see the structure of the array.
Jonah Bron
+6  A: 

You don't need any sort of override. The script is printing "Array" rather than a value, because you're trying to print to the screen a whole array, rather than a value within an array for example:

$some_array = array('0','1','2','3');

echo $some_array; //this will print out "Array"

echo $some_array[0]; //this will print "0"

print_r($some_array); //this will list all values within the array. Try it out!

print_r() is not useful for production code, because its ugly; however, for testing purposes it can keep you from pulling your hair out over nested arrays.

It's perfectly fine to access elements in your array by index: $some_array[2]

if you want it in a table you might do something like this:

<table>
    <tr>
    for($i = 0 ; $i < count($some_array) ; $i++) {
        echo '<td>'.$some_array[$i].'</td>';
    }
    </tr>
</table>
jordanstephens
+1 for a thorough answer.
Frank Farmer
I'll have to nitpick. PHP has nested arrays, not really multidimensional arrays.
Artefacto
fair enough, edited.
jordanstephens
echoing Frank F.'s comment!
eddt
A: 

A 2-dimensional table is just an array of arrays.

So, by pulling out $_SESSION["table"][0], you're pulling out an array that represents the first row of the table.

If you want a specific value from that table, you need to pass the second index, too. i.e. $_SESSION["table"][0][0]

Or you could just be lazy and do $table = $_SESSION["table"]; at which point $table would be your normal table again.

R. Bemrose