dongshun1884 2014-10-22 06:34
浏览 26

控制结构php和控制结构之间的差异javascript [关闭]

You know what are the differences between the control structure in Javascript and control structure in PHP? Both use the if / else, for or while, but that vary in that change?

Are two different programming languages ​​but there are differences in the part of "control structure" in the syntax although both are similar.

Examples

Javascript control structure

<script type="text/javascript">
    var a = 5;
    var b = 8;

    if (a < b)
    {
        alert(a +" is smaller than " +b);
    }

</script>

PHP control structure

<?php
    // Number comparison
    $a = 5;
    $b = 8;

    if ($a < $b)
    {
        echo $a ."is smaller than" .$b;
    }                
    // Result : 5 is smaller than 8
?>

Thanks

  • 写回答

2条回答 默认 最新

  • douguwo2275 2014-10-22 06:43
    关注

    Öhm, there are many big differences. The most important thing is that JavaScript runs on client side through your browser and PHP runs on server side. For PHP you need a webserver with a PHP module to understand that type of script.

    PHP code stays on the server. If you ran your PHP side the server will send you the through PHP generated HTML. The JavaScript code will be send together with this HTML to the client/Browser and after it it will be called...

    With PHP you can read your Database. With JavaScript (client-side) you can make an AJAX call to your server where a PHP script reads your Database and returns the data. Update: But JavaScript could also run server-side and then read your Database.

    PHP is often used to generate HTML. JavaScript is often used to manipulate/animate HTML.

    评论

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写