简体   繁体   English

{}的问题

[英]Issues with { }

if (Request::ajax())
        {
            $orderItemData = Input::except('_method', '_token');

            if (array_key_exists('registered_no', $orderItemData))
            **{**
            $orderItemData['status'] = ($orderItemData['registered_no'] != '' ? 'arrived' : null);

            OrderItem::where('id', $orderItemId)->update($orderItemData);

            return Response::json(array('success' => 1, 'data' => $orderItemData));
            **}**

        }

This code works fine without the { } i bold above. 这段代码工作正常,没有上面的{} i粗体。 Any idea why ? 知道为什么吗? I'm trying to do a elseif but i cant because i cant put the { } the code will fail(It doesn't response) 我正在尝试做一个elseif但我不能因为我不能把{}代码失败(它没有响应)

This: 这个:

if (condition)
    action
    anotherAction

will run anotherAction even if condition was false. 即使condition为假,也会运行anotherAction But: 但:

if (condition)
{
    action
    anotherAction
}

will not run either of the actions if condition was false. 如果condition为false,则不会运行任何一个操作。 It is up to you which actions you want executed - include them in the { .. } block and leave the rest out. 您需要执行哪些操作取决于您 - 将它们包含在{ .. }块中并将其余部分保留下来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM