Waddler
Waddler

Reputation: 219

Parse Error: unexpected T_DOUBLE_ARROW => foreach array assignment

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.

Upvotes: 2

Views: 1077

Answers (2)

Marc B
Marc B

Reputation: 360702

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

Upvotes: 0

mgraph
mgraph

Reputation: 15338

foreach ($profile_professional_experiences as $each_professional_experience) {
        $pro_xp[] = array('

Upvotes: 2

Related Questions