0

I have a problem adding data to a multidimensional array in a while loop.

My code lookes like this

while ($dataOmråde=mysql_fetch_array($område)) 
        {
            if(!in_array($dataOmråde['STED'], $aSted))
            {
                $aSted[] = $dataOmråde['STED'];
                $aOmråde[$dataOmråde['BY']]['pladsnr'] = array($dataOmråde['PLADSNR']);
            }
            else
            {
                $aOmråde[$dataOmråde['BY']]['pladsnr'] = array($dataOmråde['PLADSNR']);
            }
        }

But this keeps overwrithing my data so I get a result like this.

Array ( [Annaberg] => Array ( [pladsnr] => Array ( [0] => O_DAC_ALP_001 ) 

Bu what I want is to append data to the pladsnr array, so the result should look like this.

Array ( [Annaberg] => Array ( [pladsnr] => Array ( [0] => O_DAC_ALP_001, [1] => new pladsnr, [2] => new pladsnr second )

I have tried array_push but cant get i to work. Hopes someone can help:-)

Regards, Andreas

1
  • Can you var_dump, instead of print_r?... It might look easier to read Commented Oct 1, 2013 at 9:37

1 Answer 1

1

As you did with $aSted, do:

$aOmråde[$dataOmråde['BY']]['pladsnr'][] = $dataOmråde['PLADSNR'];
Sign up to request clarification or add additional context in comments.

1 Comment

Damn - so easy:-) Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.