{"id":1961,"date":"2017-08-26T11:16:30","date_gmt":"2017-08-26T05:46:30","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1961"},"modified":"2017-08-26T15:20:30","modified_gmt":"2017-08-26T09:50:30","slug":"dynamic-statements-using-php","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/dynamic-statements-using-php\/","title":{"rendered":"Dynamic IF statements using php"},"content":{"rendered":"<p><strong>Posted Date:26-08-2017<\/strong><\/p>\n<p>In this post we will explain eval and \u00a0Dynamic IF statements \u00a0using php<\/p>\n<p><strong>Eval:<\/strong><\/p>\n<p><span class=\"refname\">eval<\/span>\u00a0\u2014\u00a0<span class=\"dc-title\">Evaluate a string as PHP code.<\/span><\/p>\n<ul>\n<li><span class=\"dc-title\">Php code must be properly terminated using a semicolon.<\/span><\/li>\n<li>A\u00a0<em>return<\/em>\u00a0statement will immediately terminate the evaluation of the code.<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<div class=\"w3-code w3-border notranslate\">\n<div>eval(<em>phpcode<\/em>)<\/div>\n<\/div>\n<p><strong>Example:<\/strong><\/p>\n<p>Simple example of eval php using simple variables<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">$string = \"beautiful\";\r\n$time = \"world\";\r\n\r\n$str = 'This is a $string $time morning!';\r\necho $str. \"&lt;br&gt;\";\r\n\r\neval(\"\\$str = \\\"$str\\\";\");\r\necho $str;<\/pre>\n<p><a href=\"http:\/\/demo.pheonixsolutions.com\/php\/dynamic-if-condition\/simple-eval.php\">http:\/\/demo.pheonixsolutions.com\/php\/dynamic-if-condition\/simple-eval.php<\/a><\/p>\n<p>Second example, We are creating dynamic if condition using array with implode functions.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">$var1 = 11;\r\nfor ($i = 0; $i &lt;10 ; $i++) \r\n{\r\n  $condi[]=('($var1&lt;$i)');\r\n}\r\n$check=implode('||', $condi);\r\nif(eval(\"return $check;\")) \r\n{ \r\n    echo 'i is small value'; \r\n}\r\nelse\r\n{\r\n  echo 'i is big value ';\r\n}<\/pre>\n<p><a href=\"http:\/\/demo.pheonixsolutions.com\/php\/dynamic-if-condition\/\">http:\/\/demo.pheonixsolutions.com\/php\/dynamic-if-condition\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Posted Date:26-08-2017 In this post we will explain eval and \u00a0Dynamic IF statements \u00a0using php Eval: eval\u00a0\u2014\u00a0Evaluate a string as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[273],"class_list":["post-1961","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-php","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-vD","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1961"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1961\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}