{"id":6918,"date":"2022-08-17T09:53:33","date_gmt":"2022-08-17T07:53:33","guid":{"rendered":"http:\/\/blog.bart.sk\/en\/?p=6918"},"modified":"2022-11-24T14:09:59","modified_gmt":"2022-11-24T13:09:59","slug":"start-developing-php","status":"publish","type":"post","link":"https:\/\/blog.bart.sk\/en\/start-developing-php\/","title":{"rendered":"How to Start Developing in PHP"},"content":{"rendered":"<p><a href=\"https:\/\/blog.bart.sk\/php-je-stale-top-preco-je-skoro-30-rocny-jazyk-na-vrchole-rebrickov-popularity\/\"><b>In the previous article<\/b><\/a><b> you learned what PHP is and what it&#8217;s used for. In this article, we&#8217;ll focus on how to get PHP up and running and how to start developing. In simple demonstrations, we&#8217;ll show the basic constructions of the language and we&#8217;ll also talk about libraries and third-party frameworks.<\/b><\/p>\n<h2><span style=\"font-weight: 400;\">First steps<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">We need to have PHP installed before we can start writing PHP scripts. Fortunately, PHP is available for every commonly used operating system and web server. On Ubuntu OS we can install PHP using the command <\/span><i><span style=\"font-weight: 400;\">sudo apt install php<\/span><\/i><span style=\"font-weight: 400;\">. To verify that the installation was successful, we can run the <\/span><i><span style=\"font-weight: 400;\">php -v<\/span><\/i><span style=\"font-weight: 400;\"> command, which should have an output similar to this:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><span style=\"font-weight: 400;\">PHP <\/span><span style=\"font-weight: 400;\">8.1.8<\/span><span style=\"font-weight: 400;\"> (cli) (built: Jul <\/span><span style=\"font-weight: 400;\">11<\/span> <span style=\"font-weight: 400;\">2022<\/span> <span style=\"font-weight: 400;\">08<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\">29<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\">57<\/span><span style=\"font-weight: 400;\">) (NTS)<\/span>\r\n<span style=\"font-weight: 400;\">Copyright (c) The PHP Group<\/span>\r\n<span style=\"font-weight: 400;\">Zend Engine v4<\/span><span style=\"font-weight: 400;\">.1.8<\/span><span style=\"font-weight: 400;\">, Copyright (c) Zend Technologies<\/span>\r\n <span style=\"font-weight: 400;\">with Zend OPcache v8<\/span><span style=\"font-weight: 400;\">.1.8<\/span><span style=\"font-weight: 400;\">, Copyright (c), by Zend Technologies<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">A better way to develop in PHP is to use docker containers. In this way, we&#8217;ll be able to work on different projects with different versions of PHP. You can find a sample project using docker, for example, <\/span><a href=\"https:\/\/github.com\/dyarleniber\/docker-php\"><span style=\"font-weight: 400;\">here<\/span><\/a><span style=\"font-weight: 400;\">. <\/span><\/p>\n<h2><span style=\"font-weight: 400;\">PHP language basics<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">If we have PHP installed, we can start programming ? Each PHP script is &#8220;delimited&#8221; by a tag:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><b>&lt;?php<\/b>\r\n<i><span style=\"font-weight: 400;\">\/\/ PHP k\u00f3d<\/span><\/i>\r\n<b>?&gt;<\/b><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">We&#8217;ll start with the classic example of &#8220;Hello world!&#8221;. We create a &#8220;hello.php&#8221; file with the following content:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><b>&lt;?php<\/b>\r\n<span style=\"font-weight: 400;\">echo<\/span> <span style=\"font-weight: 400;\">'Hello world!'<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n<b>?&gt;<\/b><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">We simply run the script with the command &#8220;php hello.php&#8221;. The output is as follows:<br \/>\n<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9740\" src=\"https:\/\/blog.bart.sk\/wp-content\/uploads\/2022\/08\/PHP-Hello-world.png\" alt=\"PHP Hello world\" width=\"516\" height=\"38\" \/><\/p>\n<p><span style=\"font-weight: 400;\">But in order not to leave you with such a simple example, we&#8217;ll show the basic features and constructions of the PHP language. Keywords in PHP are not &#8220;case sensitive&#8221;, but it&#8217;s good to follow certain <\/span><a href=\"https:\/\/www.geeksforgeeks.org\/php-coding-standards\"><span style=\"font-weight: 400;\">standards<\/span><\/a><span style=\"font-weight: 400;\"> for clarity. Each PHP framework may have different standards for how to write code, but the basics are the same.\u00a0<\/span><\/p>\n<p><b>PHP variables start with $, can only contain alphanumeric characters, and are created the first time they are assigned a value.<\/b><span style=\"font-weight: 400;\"> PHP has weak dynamic typing, which means that the variable type is automatically assigned without declaration. In version 7, however, declarations have been added, and thus we have the possibility to determine the type of the variable. We distinguish local and global scope of variables:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><b>Global scope:<\/b><span style=\"font-weight: 400;\"> the variable is defined &#8220;everywhere&#8221;<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Local scope:<\/b><span style=\"font-weight: 400;\"> the variable is defined only in the current block (e.g. function body)<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">If we want to use a global variable in a local scope, we need to determine this using the keyword <\/span><i><span style=\"font-weight: 400;\">&#8220;global&#8221;<\/span><\/i><span style=\"font-weight: 400;\"> at the beginning of the body of the function:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><b>&lt;?php<\/b>\r\n<span style=\"font-weight: 400;\">$a = <\/span><span style=\"font-weight: 400;\">5<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">function<\/span> <b>test<\/b><span style=\"font-weight: 400;\">($b, $c = <\/span><span style=\"font-weight: 400;\">10<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 <\/span><span style=\"font-weight: 400;\">global<\/span><span style=\"font-weight: 400;\"> $a;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 <\/span><span style=\"font-weight: 400;\">static<\/span><span style=\"font-weight: 400;\"> $d = <\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 $result = $a + $b + $c + $d;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 $d++;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> $result;<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">echo<\/span><span style=\"font-weight: 400;\"> test(<\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">);; <\/span><i><span style=\"font-weight: 400;\">\/\/ v\u00fdstup 19<\/span><\/i>\r\n<span style=\"font-weight: 400;\">echo<\/span><span style=\"font-weight: 400;\"> test(<\/span><span style=\"font-weight: 400;\">5<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">5<\/span><span style=\"font-weight: 400;\">);; <\/span><i><span style=\"font-weight: 400;\">\/\/ v\u00fdstup 17<\/span><\/i>\r\n<b>?&gt;<\/b><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">However, sometimes we don&#8217;t want the local variable to be deleted. For this purpose, we can use the <\/span><i><span style=\"font-weight: 400;\">static <\/span><\/i><span style=\"font-weight: 400;\">keyword when declaring a variable, which ensures that we can work with the current value of a given variable in subsequent function calls too. In the example above, you can see that in the first call of the test function the variable <\/span><i><span style=\"font-weight: 400;\">$d<\/span><\/i><span style=\"font-weight: 400;\"> is initialized with the value 1, but at the next call it has the value 2.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the previous example, you can also see how to declare and call a function. As you may have noticed, we only used one parameter in the first function call and two in the second one. In PHP, it&#8217;s possible to assign a default value to function arguments (in the example, the default value of 10 is assigned to the <\/span><i><span style=\"font-weight: 400;\">$c<\/span><\/i><span style=\"font-weight: 400;\"> argument, which is applied if we don&#8217;t specify the value of the given argument when calling the function).<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Basic PHP elements<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Next, we&#8217;ll look at other basic elements of PHP that are essential for working with it.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">PHP data types<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Like any programming language, PHP has its built-in data types that are as follows:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><b>string:<\/b><span style=\"font-weight: 400;\"> character string<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>int:<\/b><span style=\"font-weight: 400;\"> integer value<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>float or double: <\/b><span style=\"font-weight: 400;\">a real number of single and double precision<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>bool:<\/b><span style=\"font-weight: 400;\"> logical data type (true\/false)<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>array:<\/b><span style=\"font-weight: 400;\"> field<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>null: <\/b><span style=\"font-weight: 400;\">indicates an empty value \u2013 if we declare a variable without the initial value, it will automatically have a null value<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Operators in PHP<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The operators in PHP are mostly the same as in other programming languages. More detailed explanations for each operator can be found <\/span><a href=\"https:\/\/www.w3schools.com\/php\/php_operators.asp\"><span style=\"font-weight: 400;\">here<\/span><\/a><span style=\"font-weight: 400;\">. In PHP we have the following operators:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><b>Arithmetic<\/b><span style=\"font-weight: 400;\">: +, -, *, \/, % (modulus), ** (exponent)<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Assignment<\/b><span style=\"font-weight: 400;\">: =, +=, -=, *=, \/=, %=<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Comparison<\/b><span style=\"font-weight: 400;\">: ==, ===, !=, &lt;&gt;, !==, &gt;, &lt;, &gt;=, &lt;=, \u21d4<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Increment, decrement<\/b><span style=\"font-weight: 400;\">: $x++, ++$x, $x\u2013 , \u2013$x<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Logical<\/b><span style=\"font-weight: 400;\">: &amp;&amp;, ||, !<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Concatenation of strings<\/b><span style=\"font-weight: 400;\">: ., .=<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Conditions (if\u2026else\u2026, switch)<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">If we want to execute a part of a code based on some condition, we can use the construct if\u2026else\u2026 , which has the following syntax:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (podmienka) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 k\u00f3d sa vykon\u00e1 ak podmienka je vyhodnoten\u00e1 ako pravdiv\u00e1 (<\/span><span style=\"font-weight: 400;\">true<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">} <\/span><span style=\"font-weight: 400;\">else<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 k\u00f3d sa vykon\u00e1 ak podmienka nie je pravdiv\u00e1 (<\/span><span style=\"font-weight: 400;\">false<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">}\u00a0<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">When assigning a variable value based on a condition, we can also use the so-called ternary operator <\/span><i><span style=\"font-weight: 400;\">(?:)<\/span><\/i><span style=\"font-weight: 400;\">:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><i><span style=\"font-weight: 400;\">$x = podmienka ? hodnota pre pravdiv\u00fa podmienku : hodnota pre nepravdiv\u00fa podmienku<\/span><\/i><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">If you want to execute a code according to the value of the variable and there are more options, it&#8217;s better to use the <\/span><i><span style=\"font-weight: 400;\">&#8220;switch&#8221;<\/span><\/i><span style=\"font-weight: 400;\"> construct, which will execute the desired part of the code based on the value of the variable:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><span style=\"font-weight: 400;\">switch<\/span><span style=\"font-weight: 400;\"> (n) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 <\/span><span style=\"font-weight: 400;\">case<\/span><span style=\"font-weight: 400;\"> hodnota1:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 K\u00f3d sa vykon\u00e1 ak n=hodnota1;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">break<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 <\/span><span style=\"font-weight: 400;\">case<\/span><span style=\"font-weight: 400;\"> hodnota2:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 K\u00f3d sa vykon\u00e1 ak n=hodnota2;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">break<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 <\/span><span style=\"font-weight: 400;\">case<\/span><span style=\"font-weight: 400;\"> hodnota3:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 K\u00f3d sa vykon\u00e1 ak n=hodnota3;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">break<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 ...<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 <\/span><span style=\"font-weight: 400;\">default<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 K\u00f3d sa vykon\u00e1 ak n m\u00e1 in\u00fa hodnotu ako v\u0161etky vy\u0161\u0161ie vymenovan\u00e9 hodnoty;<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span style=\"font-weight: 400;\">Cycles in PHP<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">In PHP, we have several types of cycles, which we&#8217;ll also show:<\/span><\/p>\n<p><b>While<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Executes a cycle body while the condition is true:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><span style=\"font-weight: 400;\">while<\/span><span style=\"font-weight: 400;\"> (podmienka) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 k\u00f3d ktor\u00fd sa m\u00e1 vykona\u0165<\/span>\r\n<span style=\"font-weight: 400;\">} <\/span>\r\n\r\n<span style=\"font-weight: 400;\">$i = <\/span><span style=\"font-weight: 400;\">10<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n<span style=\"font-weight: 400;\">while<\/span><span style=\"font-weight: 400;\"> ($i &gt; <\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">) {<\/span>\r\n <span style=\"font-weight: 400;\">echo<\/span><span style=\"font-weight: 400;\"> $i . PHP_EOL;<\/span>\r\n <span style=\"font-weight: 400;\">$i--;<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>Do while<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Executes the cycle body once and then continues to execute it while the condition is true:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><span style=\"font-weight: 400;\">do<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 k\u00f3d ktor\u00fd sa m\u00e1 vykona\u0165<\/span>\r\n<span style=\"font-weight: 400;\">} <\/span><span style=\"font-weight: 400;\">while<\/span><span style=\"font-weight: 400;\"> (podmienka); <\/span>\r\n\r\n<span style=\"font-weight: 400;\">$str = <\/span><span style=\"font-weight: 400;\">''<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n<span style=\"font-weight: 400;\">do<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n <span style=\"font-weight: 400;\">$str .= <\/span><span style=\"font-weight: 400;\">'a'<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n <span style=\"font-weight: 400;\">echo<\/span><span style=\"font-weight: 400;\"> $str . PHP_EOL;<\/span>\r\n<span style=\"font-weight: 400;\">} <\/span><span style=\"font-weight: 400;\">while<\/span><span style=\"font-weight: 400;\"> ($str !== <\/span><span style=\"font-weight: 400;\">'aaaa'<\/span><span style=\"font-weight: 400;\">);<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>For cycle<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The body of a cycle is executed a certain number of times \u2013 we have to define the variable that will be incremented, the condition for the end of the cycle and the method of incrementing the &#8220;counter&#8221;:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> (inicializ\u00e1cia po\u010d\u00edtadla; podmienka; inkrement\u00e1cia po\u010d\u00edtadla) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 k\u00f3d ktor\u00fd sa m\u00e1 vykona\u0165<\/span>\r\n<span style=\"font-weight: 400;\">} <\/span>\r\n\r\n<span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> ($i = <\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">; $i &lt; <\/span><span style=\"font-weight: 400;\">5<\/span><span style=\"font-weight: 400;\">; $i += <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">) {<\/span>\r\n <span style=\"font-weight: 400;\">echo<\/span><span style=\"font-weight: 400;\"> $i . PHP_EOL;<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>Foreach cycle<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Executes the cycle body for each item in an array. There are two variants of the foreach cycle:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><b>only the value of the item in the array is used in the<\/b><span style=\"font-weight: 400;\"> first one<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">in the second one,<\/span><b> in addition to the value, the key of the item in the array is also<\/b><span style=\"font-weight: 400;\"> used<\/span><\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><span style=\"font-weight: 400;\">foreach<\/span><span style=\"font-weight: 400;\"> ($pole <\/span><span style=\"font-weight: 400;\">as<\/span><span style=\"font-weight: 400;\"> $hodnota) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 k\u00f3d ktor\u00fd sa m\u00e1 vykona\u0165<\/span>\r\n<span style=\"font-weight: 400;\">} <\/span>\r\n\r\n<span style=\"font-weight: 400;\">$array = [<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\"> =&gt; <\/span><span style=\"font-weight: 400;\">'one'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\"> =&gt; <\/span><span style=\"font-weight: 400;\">'two'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\"> =&gt; <\/span><span style=\"font-weight: 400;\">'three'<\/span><span style=\"font-weight: 400;\">];<\/span>\r\n<span style=\"font-weight: 400;\">foreach<\/span><span style=\"font-weight: 400;\"> ($array <\/span><span style=\"font-weight: 400;\">as<\/span><span style=\"font-weight: 400;\"> $val) {<\/span>\r\n <span style=\"font-weight: 400;\">echo<\/span><span style=\"font-weight: 400;\"> $val . PHP_EOL;<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><span style=\"font-weight: 400;\">foreach<\/span><span style=\"font-weight: 400;\"> ($pole <\/span><span style=\"font-weight: 400;\">as<\/span><span style=\"font-weight: 400;\"> $k\u013e\u00fa\u010d =&gt; $hodnota) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 k\u00f3d ktor\u00fd sa m\u00e1 vykona\u0165<\/span>\r\n<span style=\"font-weight: 400;\">} <\/span>\r\n\r\n<span style=\"font-weight: 400;\">foreach<\/span><span style=\"font-weight: 400;\"> ($array <\/span><span style=\"font-weight: 400;\">as<\/span><span style=\"font-weight: 400;\"> $key =&gt; $val) {<\/span>\r\n <span style=\"font-weight: 400;\">echo<\/span><span style=\"font-weight: 400;\"> $key . <\/span><span style=\"font-weight: 400;\">' =&gt; '<\/span><span style=\"font-weight: 400;\"> . $val . PHP_EOL;<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">In all types of cycles, we can use the commands <\/span><i><span style=\"font-weight: 400;\">&#8220;break&#8221; and &#8220;continue&#8221;:<\/span><\/i><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><b>break<\/b><span style=\"font-weight: 400;\">: to be used if we want to interrupt the execution of the entire cycle<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>continue<\/b><span style=\"font-weight: 400;\">: to be used if we want to skip the execution of the current cycle iteration<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">In addition to the above-mentioned basic functionalities\/constructions that each programming language has in its own way, additional functionalities are also built into PHP, such as:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Working with databases<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Parsing and working with XML<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">AJAX calls<\/span><\/li>\n<\/ul>\n<h2><span style=\"font-weight: 400;\">PHP libraries<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Even with a simple PHP script we can do basically everything, we can make our work easier by using libraries or software frameworks. They provide us with a platform over which we can create our applications and they save us a lot of time, as they have implemented all the commonly used functionalities.<\/span><\/p>\n<p><b>The use of frameworks has a number of advantages:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It accelerates development<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It reduces the amount of code we would have to write ourselves<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Common functionalities are already implemented<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It makes it easier to follow good coding practices<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It&#8217;s safe<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It provides easier code maintenance<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Before we can start using any PHP framework, we need at least basic knowledge of PHP. It&#8217;s also good to know object-oriented PHP, as most frameworks are written in the OOP paradigm.<\/span><\/p>\n<p><b>The most used PHP frameworks:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Laravel (web applications)<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Zend Framework \/ Laminas Project<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Symfony<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Slim (micro framework for web applications and API)<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">In other articles in the series, we&#8217;ll give you a closer look at working with some of the frameworks.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"In the previous article you learned what PHP is and what it&#8217;s used for. In this article, we&#8217;ll&hellip;","protected":false},"author":27,"featured_media":6935,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","csco_display_header_overlay":false,"csco_singular_sidebar":"","csco_page_header_type":""},"categories":[199,211],"tags":[300,293,301],"_links":{"self":[{"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/posts\/6918"}],"collection":[{"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/comments?post=6918"}],"version-history":[{"count":1,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/posts\/6918\/revisions"}],"predecessor-version":[{"id":6919,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/posts\/6918\/revisions\/6919"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/media\/6935"}],"wp:attachment":[{"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/media?parent=6918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/categories?post=6918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/tags?post=6918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}