如何在数组中添加条件

I want to add an array condition in input field. if flag == 1 then it is a required field otherwise it is not required field

<?php echo $this->Form->input('course_workbook_answer_file', array(
    'type' => 'file',
    'label' => false,
    'id' => 'course_workbook_answer_file',
    'class' => 'form-control',
    'name' => 'data[CourseWorkbook][0][course_workbook_answer_file]',
    $port_flag == 0 ? 'required' => 'required' : Null
)); ?>

You should change your condition to value instead of complete index.

 <?php echo $this->Form->input('course_workbook_answer_file', array(
   'type' => 'file',
   'label' => false,
   'id' => 'course_workbook_answer_file',
   'class' => 'form-control',
   'name' => 'data[CourseWorkbook][0][course_workbook_answer_file]',
   'required' => ($port_flag==0)?'required':Null,
 )); ?>