Re: assign associative array values to variables? SOLVED

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

 



dg wrote:
>
> On Mar 17, 2009, at 6:47 PM, PJ wrote:
>
>> The problem is that the $array returns another array (multidimensional
>> and associative ?? )
>
>
> <?php
> $array_branch_one = array("value_one" => "red", "value_two" => "blue");
> $array_branch_two = array("value_three" => "green", "value_four" =>
> "black");
> $array_main = array("branch_one" => $array_branch_one,"branch_two" =>
> $array_branch_two);
> extract($array_main["branch_one"]);
> extract($array_main["branch_two"]);
> print "$value_one, $value_two, $value_three, $value_four";
>
> ?>
>
Thank you, once again, dg. Could not get it to work... whatever...
But I did find an unexpected solution which made things very simple.
This is the part for the categories section:

if ( isset( $book_categories[$bookID] ) ) {
    foreach ( $book_categories[$bookID] AS $categoryID ) {
        if ( isset( $category[$categoryID] ) ) {
        *$catvar = array_values($category[$categoryID]);
        $cat = $catvar[1];*
        $catn = preg_replace("/[^a-zA-Z0-9]/", "", $cat);
        echo "<a href='categories/", $catn, ".php'>", $cat,
"</a>&nbsp;&nbsp;  ";
            }
        }
    }

Because the array had keys that had various ids [number] and the value
was [category], I could not extract the category. By reassigning the
array I reset the key/value to [0] and [1]. That's in this, as above:
$catvar = array_values($category[$categoryID]);
        $cat = $catvar[1];
The rest was a piece of cake. :-) 8-)

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