Re: assign associative array values to variables?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chris wrote:
> PJ wrote:
>> 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']);
>>           }
>>       }
>>    }
>
> Same as other variable assignment.
>
> if ( isset( $category[$categoryID] ) ) {
>     $myvar = $category[$categoryID];
> }
>
> echo $myvar . "<br/>";
>
> Doing it with a multi-dimensional array is no different to a result
> set from a database or any other scenario.
>
I probably did not express myself clearly; I thought I did:
"place array * *values ** into * *$variables **"

the output of $myvar above is Array. That, I knew. And that does not
extract. I can see what is in the array in several ways; the problem is
to get the output into $var1, $var2, $var3 ... etc.  How do I convert:

$category[$categoryID]['category'] into up to 4 different variables that I can manipulate?
My code above outputs text like this: "CivilizationGods And GoddessesHistorical
PeriodsSociology & Anthropology"





-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-------------------------------------------------------------
Phil Jourdan --- pj@xxxxxxxxxxxxx
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux