PHP Programming for Beginners. Key Programming Concepts. How to use PHP with MySQL and Oracle databases (MySqli, PDO). Sergey D Skudaev

Чтение книги онлайн.

Читать онлайн книгу PHP Programming for Beginners. Key Programming Concepts. How to use PHP with MySQL and Oracle databases (MySqli, PDO) - Sergey D Skudaev страница 6

PHP Programming for Beginners. Key Programming Concepts. How to use PHP with MySQL and Oracle databases (MySqli, PDO) - Sergey D Skudaev

Скачать книгу

style="font-size:15px;">      print’ Hello Mr.”. $names [$i].”<br>”);

      }

      } //for

      print (”<br>”);

      ?>

      Output:

      The sort function sorts an array

      Hello Mrs. Anna

      Hello Mr. George

      Hello Mr. George

      Hello Mr. James

      Hello Mr. James

      Hello Mr. James

      Hello Mr. John

      Hello Mr. John

      Hello Mrs. Maria

      Hello Mr. Peter

      Hello Mr. Robert

      <?php

      echo “The array_unique function removes duplicate array values <br>”;

      $array=array ();

      $array=array_unique ($names);

      foreach ($array as $key => $value) {

      echo $key. "-”. $value. "<br>”;

      }

      print (”<br>”);

      ?>

      Output:

      The array_unique function removes duplicate values.

      0-Anna

      1-George

      3-James

      6-John

      8-Maria

      9-Peter

      10-Robert

      <?php

      rsort ($array);

      print (“The rsort function sorts an array in reverse order <br>”);

      foreach ($array as $key => $value) {

      echo $key. "-”. $value. "<br>”;

      }

      ?>

      Output:

      The rsort function sorts an array in reverse order

      0-Robert

      1-Peter

      2-Maria

      3-John

      4-James

      5-George

      6-Anna

      <?php

      print (”<br> The array_pop () functions returns the last element. <br>”);

      $lastelement=array_pop ($array);

      print (”<br> The last element=”. $lastelement.”<br>”);

      ?>

      Output:

      The array_pop () function returns the last element

      The last element=Anna

      print (”<br> Array after calling the array_pop ().

      The last element removed. <br> <br>”);

      foreach ($array as $key => $value) {

      echo $key. "-”. $value. "<br>”;

      }

      Output:

      Array after calling array_pop (): The last element removed

      0-Robert

      1-Peter

      2-Maria

      3-John

      4-James

      5-George

      The array_push function adds elements to the end of an array.

      The print_r prints array function prints array key – value pairs.

      <?php

      array_push ($array, “Chris”, “Colin”);

      print_r ($array);

      ?>

      Array after calling array_push ($array, “Chris”, “Colin”)

      and print_r functions: Chris and Colin are added to the end of the array.

      Output:

      Array ([0] => Robert [1] => Peter [2] => Maria [3] => John [4] => James [5] => George [6] => Chris [7] => Colin)

      The array_rand ($array) function returns random array index.

      $random=array_rand ($array);

      print (”<br> print array element by random

      index <br>”);

      print (”<br> Random element=”. $array [$random].”<br>”);

      Output:

      print array element by random index

      Random element=Colin

      <?php

      $string=implode ($array);

      print (”<br> Array is imploded in a string: <br>”);

      print ($string);

      ?>

      Array is imploded in a string:

      RobertPeterMariaJohnJamesGeorgeChrisColin

      The for loop

      for ($i=0; $i <10; $i++) {

      print

Скачать книгу