I want to add new array item to an existing array. I'm using array_push
for this purpose but it is not working.
Array
Array ( [productID] => 51 )
Php Code
if(isset($_REQUEST['sendProductId'])){
$inserted = $_COOKIE['productID'];
$original = $_REQUEST['sendProductId'];
if($inserted){
$cookie_value = array_push( $inserted, $original );
}else{
$cookie_value = $_REQUEST['sendProductId'];
}
$cookie_name = 'productID';
setcookie($cookie_name, $cookie_value, time() + (86400 * 30));
}
print_r($_COOKIE);
Actually I want to add products ids into a cookie. I have also used array_splice
for this but it's also not working.
Please guide me where I'm going wrong.