
{"id":7285,"date":"2022-12-25T03:28:14","date_gmt":"2022-12-25T03:28:14","guid":{"rendered":"https:\/\/tapchicntt.com\/?p=7285"},"modified":"2022-12-31T12:17:19","modified_gmt":"2022-12-31T12:17:19","slug":"php-bai-04-toan-tu-va-bieu-thuc-trong-php","status":"publish","type":"post","link":"https:\/\/tapchicntt.com\/php-bai-04-toan-tu-va-bieu-thuc-trong-php\/","title":{"rendered":"[php] B\u00e0i 04: To\u00e1n t\u1eed v\u00e0 bi\u1ec3u th\u1ee9c trong php"},"content":{"rendered":"\n<p>\u1ede b\u00e0i tr\u01b0\u1edbc ch\u00fang ta \u0111\u00e3 t\u00ecm hi\u1ec3u c\u00e1c Bi\u1ebfn &amp; Ki\u1ec3u d\u1eef li\u1ec7u trong php, v\u1eady th\u00ec trong b\u00e0i n\u00e0y ch\u00fang ta s\u1ebd \u0111i v\u00e0o s\u00e2u h\u01a1n trong l\u1eadp tr\u00ecnh php, \u0111\u00f3 l\u00e0&nbsp;to\u00e1n t\u1eed v\u00e0 bi\u1ec3u th\u1ee9c trong php. N\u1ed9i dung nh\u01b0 sau:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Bi\u1ec3u th\u1ee9c l\u00e0 g\u00ec?<\/h2>\n\n\n\n<p>Bi\u1ec3u th\u1ee9c l\u00e0 m\u1ed9t t\u1ed5 h\u1ee3p c\u00e1c to\u00e1n h\u1ea1ng v\u00e0 to\u00e1n t\u1eed. To\u00e1n t\u1eed th\u1ef1c hi\u1ec7n c\u00e1c thao t\u00e1c nh\u01b0 c\u1ed9ng, tr\u1eeb, nh\u00e2n, chia, so s\u00e1nh, \u2026 <\/p>\n\n\n\n<p>To\u00e1n h\u1ea1ng l\u00e0 nh\u1eefng bi\u1ebfn hay l\u00e0 nh\u1eefng gi\u00e1 tr\u1ecb m\u00e0 c\u00e1c ph\u00e9p to\u00e1n \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n tr\u00ean n\u00f3.<\/p>\n\n\n\n<p>V\u00ed d\u1ee5 <code>$a + $b<\/code>&nbsp;th\u00ec&nbsp;<code><samp>$a<\/samp><\/code>&nbsp;v\u00e0&nbsp;<code>$b<\/code>&nbsp;\u0111\u01b0\u1ee3c g\u1ecdi l\u00e0 to\u00e1n h\u1ea1ng, d\u1ea5u&nbsp;<code><strong>+<\/strong><\/code>&nbsp;\u0111\u01b0\u1ee3c g\u1ecdi l\u00e0 to\u00e1n t\u1eed, c\u1ea3 2 k\u1ebft h\u1ee3p l\u1ea1i th\u00e0nh m\u1ed9t bi\u1ec3u th\u1ee9c&nbsp;<code>($a + $b)<\/code>.<\/p>\n\n\n\n<p>M\u1ed7i bi\u1ec3u th\u1ee9c ch\u1ec9 c\u00f3 m\u1ed9t gi\u00e1 tr\u1ecb nh\u1ea5t \u0111\u1ecbnh. V\u00ed d\u1ee5 ta c\u00f3 bi\u1ec3u th\u1ee9c&nbsp;<code>($a + $b)<\/code>&nbsp;th\u00ec bi\u1ec3u th\u1ee9c n\u00e0y c\u00f3 gi\u00e1 tr\u1ecb l\u00e0 t\u1ed5ng c\u1ee7a&nbsp;<code>$a<\/code>&nbsp;v\u00e0&nbsp;<code>$b<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">To\u00e1n t\u1eed g\u00e1n (Assignment Operator):<\/h3>\n\n\n\n<p>\u0110\u00e2y l\u00e0 to\u00e1n t\u1eed th\u00f4ng d\u1ee5ng nh\u1ea5t trong m\u1ecdi ng\u00f4n ng\u1eef, ta d\u00f9ng d\u1ea5u <code>=<\/code> \u0111\u1ec3 g\u00e1n gi\u00e1 tr\u1ecb cho m\u1ed9t bi\u1ebfn b\u1ea5t k\u1ef3 n\u00e0o \u0111\u00f3.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>$a = 19;<\/p>\n<\/blockquote>\n\n\n\n<p>B\u1ea1n c\u00f3 th\u1ec3 g\u00e1n nhi\u1ec1u bi\u1ebfn c\u00f9ng m\u1ed9t gi\u00e1 tr\u1ecb qua m\u1ed9t c\u00e2u l\u1ec7nh \u0111\u01a1n l\u00e0 g\u00e1n li\u00ean ti\u1ebfp.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>$a = $b = $c = 19;<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Bi\u1ec3u th\u1ee9c s\u1ed1 h\u1ecdc<\/h3>\n\n\n\n<p>C\u00e1c ph\u00e9p to\u00e1n th\u01b0\u1eddng \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n theo m\u1ed9t th\u1ee9 t\u1ef1 c\u1ee5 th\u1ec3 g\u1ecdi l\u00e0 \u0111\u1ed9 \u01b0u ti\u00ean \u0111\u1ec3 \u0111\u01b0a ra gi\u00e1 tr\u1ecb cu\u1ed1i c\u00f9ng. C\u00e1c bi\u1ec3u th\u1ee9c s\u1ed1 h\u1ecdc trong c\u00e1c ng\u00f4n ng\u1eef \u0111\u01b0\u1ee3c th\u1ec3 hi\u1ec7n b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng c\u00e1c to\u00e1n t\u1eed s\u1ed1 h\u1ecdc c\u00f9ng v\u1edbi c\u00e1c to\u00e1n h\u1ea1ng d\u1ea1ng s\u1ed1 ho\u1eb7c k\u00fd t\u1ef1 (bi\u1ebfn). Nh\u1eefng bi\u1ec3u th\u1ee9c n\u00e0y g\u1ecdi l\u00e0 bi\u1ec3u th\u1ee9c s\u1ed1 h\u1ecdc.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>$c = $a + $b\/2<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">2. To\u00e1n t\u1eed quan h\u1ec7<\/h2>\n\n\n\n<p>To\u00e1n t\u1eed quan h\u1ec7 c\u0169ng l\u00e0 m\u1ed9t \u0111\u1ecbnh ngh\u0129a trong b\u00e0i to\u00e1n t\u1eed v\u00e0 bi\u1ec3u th\u1ee9c trong php, \u0111\u01b0\u1ee3c d\u00f9ng \u0111\u1ec3 ki\u1ec3m tra m\u1ed1i quan h\u1ec7 gi\u1eefa hai bi\u1ebfn hay gi\u1eefa m\u1ed9t bi\u1ebfn v\u00e0 m\u1ed9t h\u1eb1ng s\u1ed1. V\u00ed d\u1ee5 ki\u1ec3m tra 2 bi\u1ebfn&nbsp;<code>$a<\/code>&nbsp;v\u00e0&nbsp;<code>$b<\/code>&nbsp;xem bi\u1ebfn n\u00e0o l\u1edbn h\u01a1n ta l\u00e0m nh\u01b0 sau:&nbsp;<code>($a &gt; $b)<\/code>&nbsp;v\u00e0 k\u1ebft qu\u1ea3 c\u1ee7a bi\u1ec3u th\u1ee9c n\u00e0y s\u1ebd tr\u1ea3 v\u1ec1 ki\u1ec3u boolean <code>TRUE<\/code> ho\u1eb7c <code>FALSE<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-regular\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">To\u00e1n T\u1eed<\/td><td class=\"has-text-align-center\" data-align=\"center\">Gi\u00e1 tr\u1ecb<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">&gt;<\/td><td class=\"has-text-align-center\" data-align=\"center\">L\u1edbn h\u01a1n<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">&lt;<\/td><td class=\"has-text-align-center\" data-align=\"center\">Nh\u1ecf h\u01a1n<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">==<\/td><td class=\"has-text-align-center\" data-align=\"center\">B\u1eb1ng<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">>=<\/td><td class=\"has-text-align-center\" data-align=\"center\">L\u1edbn h\u01a1n ho\u1eb7c b\u1eb1ng<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">&lt;=<\/td><td class=\"has-text-align-center\" data-align=\"center\">Nh\u1ecf h\u01a1n ho\u1eb7c b\u1eb1ng<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u1ede b\u00e0i tr\u01b0\u1edbc ch\u00fang ta \u0111\u00e3 t\u00ecm hi\u1ec3u c\u00e1c Bi\u1ebfn &amp; Ki\u1ec3u d\u1eef li\u1ec7u trong php, v\u1eady th\u00ec trong b\u00e0i [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":4572,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[178],"tags":[],"class_list":["post-7285","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"views":830,"_links":{"self":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/7285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/comments?post=7285"}],"version-history":[{"count":7,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/7285\/revisions"}],"predecessor-version":[{"id":7304,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/7285\/revisions\/7304"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media\/4572"}],"wp:attachment":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media?parent=7285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/categories?post=7285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/tags?post=7285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}