1

I am storing some value in multidimensional array, while storing that iam trying to neglate duplicate array in my values for that i used array_unique function in php. Its working in local, but not working in live can any one help me. I have attached my code below

$ex = $_POST;



$_SESSION["cartdetail"][] = $ex;



$_SESSION["cartdetail"] = array_unique($_SESSION["cartdetail"]);

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

outPut

Array
(
[0] => Array
    (
        [cid] => 7
        [cname] => studies 
        [ctype] => Class Room
        [cdate] => 12-1
        [ctime] => 09:30 am-06:30 pm
        [cdays] => 5
        [cprice] => 1
        [viewDetails] => start
    )

)

When i am trying to store different value in array, its not storing. Its storing only first value in array.Thank for your help

Vijaykarthik
  • 333
  • 4
  • 10
  • 25

1 Answers1

0

You need to serialize the internal arrays and then unserialize back:

$_SESSION["cartdetail"] = array_map("unserialize", array_unique(array_map("serialize", $_SESSION["cartdetail"])));
n-dru
  • 9,285
  • 2
  • 29
  • 42