Re: assign associative array values to variables?

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

 



dg wrote:
> If I'm understanding your question correctly, this may help:
>
> <?php
>
> $array = array("value_one" => "red", "value_two" => "blue");
> extract($array);
> print "$value_one, $value_two";
>
Thanks for the suggestion. I've seen that example and have tried it as
well as about a dozen others.
The problem is that the $array returns another array (multidimensional
and associative ?? )
print_r($myarray) returns for example:

Array ( [id] => 5 [category] => Some category)
Array ( [id] => 33 [category] => Another category)

So, you see, I can't do anything with that. I had hoped to be able to
use something like count() or $row() or foreach or while but no go.
foreach may have a possibility but it it rather convoluted and I'm
trying to avoid it; hoping for something simpler, more logical and more
"elegant".
> ?>
> On Mar 17, 2009, at 4:27 PM, 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']);
>>          }
>>      }
>>   }
>>
>> 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@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
>>
>
>


-- 
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