2

I have the following code.

$getPoetry['poet'] = $_SESSION[$member]['filters']['newspaper'] = array(
    '$in' => $allFollowing
);

$getPoetry['poet'] has the complete array inside while $_SESSION[$member]['filters']['newspaper'] does not.

What might be the problem?

When I print the array $_SESSION[$member] exists but it's a key with an empty array

Thirumalai murugan
  • 5,698
  • 8
  • 32
  • 54
Joshua
  • 79
  • 1
  • 8

2 Answers2

2

Try this one

<?php   
    session_start();

    // create an array
    $my_array=array('cat', 'dog', 'mouse', 'bird', 'crocodile', 'wombat', 'koala', 'kangaroo');

    // put the array in a session variable
    $_SESSION['animals']=$my_array;

    // a little message to say we have done it
    echo 'Putting array into a session variable';

    // loop through the session array with foreach
    foreach($_SESSION['animals'] as $key=>$value)
        {
        // and print out the values
        echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />';
        }
    ?>

Your example I have given some value to the variable what ever you used

<?php
session_start();
$member = 'new';
$allFollowing = 'follower';
$getPoetry['poet'] = $_SESSION[$member]['filters']['newspaper'] = array('$in' => $allFollowing);
print_r($_SESSION[$member]['filters']['newspaper']);
print_r($getPoetry);
?>

@Yogesh Suthar case he missed key and 0 should not be in the sessions first key check that too

<?php   
session_start();
$abcd = $_SESSION['test']['filters']['newspaper'] = array('test'=>"abcd");
print_r($_SESSION['test']['filters']['newspaper']);
print_r($abcd);
?>
Thirumalai murugan
  • 5,698
  • 8
  • 32
  • 54
0

It is working properly. I think you haven't start the session use session_start(); at top of page

session_start();

$abcd = $_SESSION[0]['filters']['newspaper'] = array("abcd");

print_r($_SESSION[0]['filters']['newspaper']);
print_r($abcd);

output as below

Array ( [0] => abcd ) Array ( [0] => abcd ) 
Thirumalai murugan
  • 5,698
  • 8
  • 32
  • 54
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100