List piemērs 2 - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of List piemērs 2.php

  1. <?php
  2.     $myList = [
  3.         'This',
  4.         'is',
  5.         'a',
  6.         'lot',
  7.         'of',
  8.         'seperate',
  9.         'list',
  10.         'items',
  11.         'and',
  12.         'you',
  13.         'can',
  14.         'add',
  15.         'any',
  16.         'extra',
  17.         'how',
  18.         'mutch',
  19.         'you',
  20.         'want',
  21.     ];
  22.     
  23.     echo makeList($myList);
  24.     echo makeList($myList,true);
  25.     echo makeList($myList,false,true);
  26.     
  27.     function makeList($data, $ucFirst = false, $ucAll = false) {
  28.         $rc = '';
  29.         $rc .= '<ul style="margin-bottom:1em;">';
  30.         foreach($data as $oneItem) {
  31.             if($ucAll) {
  32.                 $oneItem = strtoupper($oneItem);
  33.             }
  34.             if($ucFirst) {
  35.                 $oneItem = ucfirst($oneItem);
  36.             }
  37.             $rc .= '<li>'.$oneItem.'</li>';
  38.         }
  39.         $rc .= '</ul>';
  40.         return $rc;
  41.     }
  42. ?>
File Description
  • List piemērs 2
  • PHP Code
  • 15 Sep-2021
  • 870 Bytes
You can Share it: