Dysan Posted November 22, 2007 Share Posted November 22, 2007 Why doesn't the amount of values in the array get displayed, to reflect what in the array, upon calling the writeShoppingCart() function? - The amount stays at 0, Why is this? <?php session_start(); function writeShoppingCart() { echo count($array); } if(isset($_SESSION['ids']) && is_array($_SESSION['ids'])) { $array = $_SESSION['ids']; } else { $array = array(); } if (!in_array($_GET['id'], $array)) { $array[] = $_GET['id']; } else { echo "ID Exists"; } $_SESSION['ids'] = $array; writeShoppingCart(); print_r($array); ?> Link to comment https://forums.phpfreaks.com/topic/78469-not-working/ Share on other sites More sharing options...
kratsg Posted November 22, 2007 Share Posted November 22, 2007 I'm going to assume because you ended the function right after that first echo statement....? Is the error that when you call the function, you get "0" or the fact that the array is not being built? Also, you need to pass the variable $array into the function in order for it to access it.. try adding a global: function writeShoppingCart() { global $array; Link to comment https://forums.phpfreaks.com/topic/78469-not-working/#findComment-397072 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.