Jump to content

[SOLVED] Outputting an array


wemustdesign

Recommended Posts

I have looked on the Internet but cannot find an array example that suits my needs. The array that I am outputting in a 'add to favorites' similar to a shopping cart. I am currently outputting the array using the code below. This output ok but doesn't work when removing the items from the favorites via a query string. What I need is something that will output the array and the array key within a query string like '&remove_from_favotites&id=$ARRAY_KEY"

 

$i=0;
while ($i < $favorites_Size){
echo $_SESSION['favoriteArray'][$i]." 
<a href=$url&function=remove_favorite&cocktail=$favoritesArray[$i]&ai=$i>[x]</a><br />";
$i++;
}

Link to comment
https://forums.phpfreaks.com/topic/149080-solved-outputting-an-array/
Share on other sites

No this does not work. I thik I can see where the problem is. When I output the array it outputs like below with the querystring matching the array key

 

(Array key [0])Cocktail     remove=0
(Array key [1])Cocktail1   remove=1
(Array key [2])Cocktail2   remove=2

 

If I delete Cocktail1 from the favorites it then outputs like this:

 

(Array key [0])Cocktail     remove=0
(Array key [2])Cocktail2   remove=1

 

This is because the querystring is generated by $i. I need the querystring to output the same value as the arraykey if you know what I men

 

Sorry if I've misunderstood what you want to do, but this should do the trick.

 

$theArray[0] = "Cocktail";
$theArray[1] = "Cocktail1";
$theArray[2] = "Cocktail2";

foreach( $theArray as $arrayKey => $arrayValue )
	echo $arrayValue." <a href=$url&function=remove_favorite&cocktail=" . $arrayValue . "&ai=" . $arrayKey . ">[x]</a><br />";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.