Skip to main content

Posts

Showing posts from January, 2018

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 type of ways. For getting only array values. For getting both key and va

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()  function is used get the array of elements in the r