-2

Can someone help me to fix this code.

this is data array for a CSV file

foreach($feedback as $value) {
        $csv_array[] = array(
            'title' => $value->title ?: get_the_title($value->post_id),
            'feedback_type' => $value->type,
            'reason' => $value->reason,
            'comments' => $value->comments,
            'allow_response' => $value->allow_response === null ? 'No' : 'Yes',
            'firstname' => $value->first_name,
            'lastname' => $value->last_name,
            'phone' => $value->phone,
            'email' => $value->email,
            'prefered_contact_method' => $value->prefered_contact_method,
            'date_submitted' => $value->created_at
        );
    }

Now I want to know if feedback_type is negative 'reason' => $value->reason this needs to be empty.

I write this, but looks like something is wrong.

'feedback_type' => $value->type === 'negative' ? 'reason' => $value->reason : ''
Nara
  • 145
  • 1
  • 5

1 Answers1

1

if type is negative then empty , else use $value->reason

'reason' => $value->type === 'negative' ? '' : $value->reason
               
Xun
  • 377
  • 1
  • 7