assign associative array values to variables?

From: Date: Tue, 17 Mar 2009 23:27:52 +0000
Subject: assign associative array values to variables?
Groups: php.general 
Request: Send a blank email to php-general+get-290190@lists.php.net to get a copy of this message
I have been tearing out my hair to figure out a way to place array values into $variables with not much luck. I can echo the array to the screen but I can not manipulate the results. I have searched wide and far all day on the web and I find nothing that points the way how to extract values from an associative array and assign them to a variable. I expected to find some elegant way to do it. Here's the code that outputs the values: if ( isset( $book_categories[$bookID] ) ) { foreach ( $book_categories[$bookID] AS $categoryID ) { if ( isset( $category[$categoryID] ) ) { echo($category[$categoryID]['category']); } } } this will echo something like "CivilizationGods And GoddessesHistorical PeriodsSociology & Anthropology" (I have not added breaks beween the categories as there is more manipulation needed on them) This works for as many categories as needed. Manipulating each value should not be a problem once it is in a string variable using switch and preg_replace() as each category needs to be stripped of spaces, commas and &s. -- unheralded genius: "A clean desk is the sign of a dull mind. " ------------------------------------------------------------- Phil Jourdan --- pj@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php

« previous php.general (#290190) next »