Re: Multi dimensional array

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

 



On Sun, 2015-08-02 at 23:19 -0400, Ron Piggott wrote:
> How do I correctly make "category_assignment" into a multi dimensional 
> array:
> 
> if(is_array($result) &&count($result) >'0') {
>      foreach($resultAS$value) {
>          $array= [
>              'reference'=>$value['reference'],
>              'introductory_paragraph'=>$value['introductoryParagraph'],
>              'category_assignment'=>array[][$value['category'] =>$value['categoryLink'] ]
>          ];
>      }
> }
> 
> Ron
> 

I would imagine you're after something like this:

if(is_array($result) && count($result) > 0)
{
    foreach($result as $value)
    {
        $array= (
            'reference' => $value['reference'],
            'introductory_paragraph' => $value['introductoryParagraph'],
            'category_assignment' =>
                array(
                    $value['category'] => $value['categoryLink'],
                ),
        );
     }
}

I also amended the second clause of the if statement, as you were
comparing an integer to the string 0, and comparing numbers to strings
like that doesn't always work as you want or expect.

The main thing I think you missed was that array constructs use () and
not [] in their creation, which you were using in both of your arrays,
that way is a little more how Javascript does it.

Thanks,
Ash

http://www.ashleysheridan.co.uk




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