0

I have following array:

Array
(
[WEEK_DAYS] => Array
    (
        [DEF] => Array
            (
                [0] => 08:00
                [1] => 20:00
            )

        [0] => Array
            (
                [0] => 08:01
                [1] => 20:01
            )
    )

[EXCEPTS] => Array
    (
        [0] => 2016-5-30
        [1] => 2016-6-20
        [2] => 2016-5-25
        [3] => 2016-6-5
    )
)

And following string on PHP:

 $form = <<<END
      <input class="form-control" name="title" type="text" id="title" value="$formData['WEEK_DAYS']['DEF'][0]">
 END;

When i use from this structure it will return error, how i can put this array index in my string. i can put it on variable and use from that variable but my indexes is too much and it take resource from server.

I see

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING ) or variable (T_VARIABLE) or number (T_NUM_STRING) error

3
  • I have tried your code its working fine. Commented May 23, 2016 at 7:02
  • I see <b>Parse error</b>: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING ) or variable (T_VARIABLE) or number (T_NUM_STRING) Commented May 23, 2016 at 7:05
  • 1
    You should put your variables inside curly braces like this: value="{$formData['WEEK_DAYS']['DEF'][0]}" Commented May 23, 2016 at 7:07

1 Answer 1

2

Use proper quotes in $form.

$arr = Array
(
"WEEK_DAYS" => Array
    (
        "DEF" => Array
            (
                0 => "08:00",
                1 => "20:00"
            ),
        0 => Array
            (
                0 => "08:01",
                1 => "20:01"
            )
    ));

echo $arr["WEEK_DAYS"]["DEF"][0];
$form = '<input class="form-control" name="title" type="text" id="title" value="'.$arr['WEEK_DAYS']['DEF'][0].'">';

Use {} for structure.

$form = <<<END
      <input class="form-control" name="title" type="text" id="title" value="{$formData['WEEK_DAYS']['DEF'][0]}">
 END;

Output

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

thank you but i am force to use <<< structure and can not define like you($form = '')
check my edited code. @MajidAbbasi

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.