Skip to main content

Posts

Showing posts with the label open tags in php

Foreach Loop in PHP

In PHP,  foreach  statement is used to iterate over a collection of data, like  PHP arrays . As per the name of this construct, it will keep on continue with the loop to traverse given input array for each of its element, without any condition. We have slightly touched about how this is working in PHP while seeing about  PHP loops . In this article, let us see about  foreach  statement with more details. Unlike other PHP loop statements,  while ,  do..while  and  for , this PHP loop statement  foreach  contains no counters, conditions and no need of increments or decrements, explicitly. Rather, it will iterate with each element and will be useful, where all the elements of the array to be traversed unconditionally. foreach  Usage in PHP Script We can use  foreach  statement in a PHP program with two various syntaxes differed based on the iteration behavior for getting array elements in the following t...

Arrays In PHP

Have you ever heard about Array.A n Array is a   PHP datatype  used to store a group of data into a variable. Each array item is stored as a key and value pair. Arrays are classified as “indexed array” and “associative array” based on the key specification. The Indexed array has default index starts with ‘0’ and the associative array contains the user-defined key index. The array can also be classified as “one-dimensional array” and “multi-dimensional array” based on the level of the array index. In this tutorial, we are going to see some of the important array functions in PHP. PHP Array Functions In this section, we are going to see some of the widely used PHP array functions. I explain the purpose of the array functions, the parameter it requires and the default values of the parameter. This section includes small and simple PHP code snippets to explain the usage of each array function.  range(start, end) PHP  range()  fu...

PHP opening Tags

PHP delimiters are nothing but the open close tags to enclose PHP script. PHP code can be parsed if and only if it is enclosed with these delimiters. There are various set of delimiters to recognize PHP code. These are as listed below. <?php … ?>  – It is most probably used delimiters and also preferable, since, PHP code enclosed with in <?php .. ?> could be recognized with other PHP servers independent of the tag related configuration directives. <script language=”php”></script>  – This will also work anywhere, like <?php … ?>. <? … ?>  – This is called as PHP short tags which will work based on the value set with  short_open_tag  directive of PHP configuration file. <?=..;?>  – This is also short form of denoting PHP code, but used as an alternative representation of PHP print statement. <% … %>  or  <%=;%>    – This is the delimiters for writing Active Server Pages(A...