{"id":335,"date":"2020-11-15T15:02:50","date_gmt":"2020-11-15T15:02:50","guid":{"rendered":"https:\/\/demo.wpartisan.net\/developmentsite\/programming-with-php\/create-pyramid-using-asterisks-in-php\/"},"modified":"2024-10-28T04:29:24","modified_gmt":"2024-10-28T04:29:24","slug":"create-pyramid-using-asterisks-in-php","status":"publish","type":"programming_with_php","link":"https:\/\/demo.wpartisan.net\/developmentsite\/programming-with-php\/create-pyramid-using-asterisks-in-php\/","title":{"rendered":"Create Pyramid Using asterisks in PHP"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Use 2 &#8216;for loops&#8217; with conditions and a &#8216;while loop&#8217; like the one below. You must specify the pyramid&#8217;s height using a variable like $height = 5; first.<\/p>\n\n\n\n<pre class=\"wp-block-code \\&quot;wp-block-code\\&quot;\"><code lang=\"\\&quot;php\\&quot;\" class=\"language-\\&quot;php\\&quot;\">$height = 5;\nfor( $i=$height; $i>=1; $i-- ){\n\tfor( $j=1; $j&lt;=$height; $j++ ){\n\t\tif( $j >= $i ){\n\t\t\techo '*';\n\t\t\tif( $j == $height ){\n\t\t\t\t$diff = $j - $i;\n\t\t\t}\n\t\t}else{\n\t\t\techo '&amp;nbsp;&amp;nbsp;';\n\t\t}\n\t}\n\t$k = 0;\n\twhile( $k &lt; $diff ){\n\t\techo '*';\n\t\t$k++;\n\t}\n\techo '&lt;br\/>';\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">OUTPUT:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full \\&quot;wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"106\" height=\"105\" src=\"https:\/\/demo.wpartisan.net\/developmentsite\/wp-content\/uploads\/2020\/11\/pyramid.png\" alt=\"\" class=\"wp-image-2256\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>To create a pyramid using asterisks in PHP, first, we need to specify the pyramid&#8217;s height using a variable like $height = 5. Then we need to add two &#8216;for loop&#8217; and one &#8216;while loop&#8217; like below:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","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":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"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":""},"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-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":"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":""},"mobile":{"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":""}}},"class_list":["post-335","programming_with_php","type-programming_with_php","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"WPArtisan","author_link":"https:\/\/demo.wpartisan.net\/developmentsite\/author\/developmentsiteauth\/"},"uagb_comment_info":0,"uagb_excerpt":"To create a pyramid using asterisks in PHP, first, we need to specify the pyramid's height using a variable like $height = 5. Then we need to add two 'for loop' and one 'while loop' like below:","_links":{"self":[{"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/programming_with_php\/335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/programming_with_php"}],"about":[{"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/types\/programming_with_php"}],"author":[{"embeddable":true,"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/comments?post=335"}],"wp:attachment":[{"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/media?parent=335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}