2 Replies - 159 Views - Last Post: 11 January 2020 - 12:17 PM Rate Topic: -----

#1 makamo66   User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 104
  • Joined: 04-February 09

var_dump of an array shows just one variable

Posted 11 January 2020 - 10:49 AM

The var_dump of the $cart_items array is supposed to show an array of $cart_items with the quantities added together for the same id but it doesn't even show an array, it just shows one value.

session_start();
$cart_items = $_SESSION["cart_items"];
if ( $cart_items == null ) {
	$cart_items = array();
}
if ( isset($_REQUEST["element_id"]) ) {
	$id = $_REQUEST["element_id"];
}

if ( isset($_REQUEST["quantity"]) ) {
	$quantity = $_REQUEST["quantity"];
}

if ( isset($id)  && isset($quantity) ) {
if (isset($cart_items[$id])) {
	  	$cart_items[$id] += $quantity;

} else {
    $cart_items[$id] = $quantity;
}
}
var_dump($cart_items);



Is This A Good Question/Topic? 0
  • +

Replies To: var_dump of an array shows just one variable

#2 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 3070
  • View blog
  • Posts: 11,779
  • Joined: 03-December 12

Re: var_dump of an array shows just one variable

Posted 11 January 2020 - 11:11 AM

Okay?
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3826
  • View blog
  • Posts: 13,946
  • Joined: 08-August 08

Re: var_dump of an array shows just one variable

Posted 11 January 2020 - 12:17 PM

You never set your session variable, so when you read from it, it's empty.
https://www.php.net/...ssion-start.php
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1