PHP Question

How to get names and values of cookies from PHP

I'm coding an e-commerce website that uses cookies to transfer information from the product page to the cart.

has all of the cookies for a certain page put into an array, with the name of the cookie and the the value of the cookie. Example:

array(2) { ["0_USB_Keyboard"]=> string(6) "$19.99" ["0_Alarm_Clock_Radio"]=> string(6) "$14.99" }

How can I take each cookie name and put them in an new array, so they can be used elsewhere. And how can I put each cookie value in an new array, so that they too can be used else where?

Answer Source

// Edit
Use array_keys and array_values

$array = array( 
 "0_USB_Keyboard" => "$19.99", 
 "0_Alarm_Clock_Radio" => "$14.99"


Output would be:

    [0] => 0_USB_Keyboard
    [1] => 0_Alarm_Clock_Radio
    [0] => $19.99
    [1] => $14.99

I hope this helps you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download