问题
I have a cart session stored in $_SESSION['cart'] that store the book's data (book_name, book_image, book_price, etc) if the user click 'buy'. I want to display the book_name only using this code :
foreach ($_SESSION['cart'] as $key => $value) {
echo implode(', ', $key);
}
but it return into invalid arguments passed. I know that $key
variable store the book name, and the $key
variable store how much the book's amount.
What i want is display the items into one string like this
book1, book2, book3
and then store it into one table row in my database like this :
book_name | total_price | etc..
----------------------------+-------------+------
book1, book2, book3 | 120000 | ....
So the conclusion of my problems above is :
- How to convert the book_name that is an associative array into one string?
- Then how to store the book_name (that has been 'converted' to one string) into one table row?
Anyone can help me? Thanks in advance :)
来源:https://stackoverflow.com/questions/41205252/convert-associative-array-in-php-and-insert-it-to-database