0

I'm having trouble adding this

<?php echo (set_value('first_name')) ? (set_value('first_name')) : ($row->first_name); ?>

to the value item in the following array

$first_name = array(
              'name'        => 'first_name',
              'id'          => 'first_name',
              'value'       => ' ',
              'maxlength'   => '20',             
              'class'       => 'text',

            );

I tried using quotes and other methods but I get errors. How should I format it for array?

1
  • value, sorry. i get syntax error Commented May 27, 2011 at 2:19

1 Answer 1

4

Do you mean like this?

$set_first_name = set_value('first_name');
$first_name = array(
    'name' => $set_first_name ? $set_first_name : $row->first_name,
    // etc

If using PHP 5.3, you can even shorten that to

'name' => $set_first_name ?: $row->first_name
Sign up to request clarification or add additional context in comments.

1 Comment

oh i see! There's no need to add 'echo' in array value. 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.