2

I am trying to create an associative array that collects the following (existing on the db) information using this code:

$pro_xp = array();//array declaration
foreach ($profile_professional_experiences as $each_professional_experience) {
        $pro_xp[] = ('title' => $each_professional_experience->title,
                     'company' => $each_professional_experience->company,
                     'industry' => $eachprofessional_experience->industry,
                     'time_period' => $each_professional_experience->time_period,
                     'duration' => $each_professional_experience->duration);}

This current code wins me a Parse Error message, which is not productive for me. I have seen other assignment questions, but none like this. I'm still new to PHP development, so if this is a rookie mistake, that would be why.

3
  • 5
    I think if you look again, you will find you forgot the word array... Commented Mar 20, 2012 at 15:33
  • I didn't think I needed it since I had declared it above. I thought I was placing those items into the array at that position. BUT, I have to place an array (with those items) into my original array. Commented Mar 20, 2012 at 15:47
  • You still need the array keyword. You are creating a sub-array, but it is still a new array. $var = ('val', 'val'); is not a valid PHP syntax. Commented Mar 20, 2012 at 15:49

2 Answers 2

2
foreach ($profile_professional_experiences as $each_professional_experience) {
        $pro_xp[] = array('
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. That got me rolling again.
0
    $pro_xp[] = array('title' => $each_professional_experience->title,
                ^^^^^---add this

without the array bit, PHP doens't know you want an array. Something like

$x = ("Hello");

is perfectly valid, but isn't defining an array. It's just a string assignment. Unless you're in an array definition context, the => arrow operator isn't valid.

Comments

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.