Image

PHP/MySQL / Code (page 2)

BEGINNER

C 0009 - Math (sqrt function)
Reproduce this code (do not copy and paste!).

<!DOCTYPE html>
<html>
<body>
<?php
echo(sqrt(24) . "<br>");
echo(sqrt(9) . "<br>");
echo(sqrt(22) . "<br>");
echo(sqrt(8));
?>
</body>
</html>
C 0010 - Magical constant (namespace)
Reproduce this code (do not copy and paste!).

<?php
namespace allMyPassions;
function myValue(){
  return __NAMESPACE__;
}
?>
<!DOCTYPE html>
<html>
<body>
<?php
echo myValue();
?>
</body>
</html>
C 0011 - Strings (word count)
Reproduce this code (do not copy and paste!).

<!DOCTYPE html>
<html>
<body>
<?php
echo str_word_count("My planet is so far away !");
?> 
</body>
</html>
C 0012 - Concatenate
Reproduce this code (do not copy and paste!).

<!DOCTYPE html>
<html>
<body>
<?php
$x = "Just";
$y = "Code !";
$z = "$x $y";
echo $z;
?>
</body>
</html>
C 0013 - Constant
Reproduce this code (do not copy and paste!).

<!DOCTYPE html>
<html>
<body>
<?php
define("Welcome", "How are you ?");
function myConstant() {
  echo Welcome;
}
myConstant();
?> 
</body>
</html>
C 0014 - Echo/Print
Reproduce this code (do not copy and paste!).

<!DOCTYPE html>
<html>
<body>
<?php
$txt1 = "How's the weather ?!";
$txt2 = "sunny !";
print '<h2>' . $txt1 . '</h2>';
print '<p>We should go for a walk because it is ' . $txt2 . '</p>';
?>
</body>
</html>
C 0015 - Functions (... operator)
Reproduce this code (do not copy and paste!).

<!DOCTYPE html>
<html>
<body>
<?php
function sumMyNumbers(...$x) {
  $n = 0;
  $len = count($x);
  for($i = 0; $i < $len; $i++) {
    $n += $x[$i];
  }
  return $n;
}
$a = sumMyNumbers(16, 6, 20, 8, 109, 17);
echo $a;
?>
</body>
</html>
C 0016 - Functions (... operator)
Reproduce this code (do not copy and paste!).

<!DOCTYPE html>
<html>
<body>
<?php
function sumMyNumbers(...$x) {
  $n = 0;
  $len = count($x);
  for($i = 0; $i > $len; $i++) {
    $n += $x[$i];
  }
  return $n;
}
$a = sumMyNumbers(16, 6, 20, 8, 109, 17);
echo $a;
?>
</body>
</html>
Image

CHOOSE YOUR COMPILER

Reproduce this code, choosing one of the compilers below (don't copy and paste! It would be too easy). They all have the same function, just choose one according to your preferences.

When copying your code, replace the existing (default) code already in the compiler with your own.

Warning ! Choose the compiler based on the formatting (e.g., with or without HTML tags). For some of these compilers, you must choose the programming language yourself from the menu that is then offered. Of course, don't forget to click on RUN !

Responsibility

Some of the external links presented below, are not under the direct responsibility of Fond of Code. We cannot therefore be held responsible for the quality/Viability, or the temporary nor permanent interruption of some of them.

All about PHP

Code

Recent versions

Frameworks

Tools/Methodologies

Test

Info+

» Creation date: 1994
* Created by Rasmus Lerdorf
* Developed by The PHP Group
* Influenced by C/C ++, Java and PERL
* Written in C

* Cross-platform
* Free license / PHP license

News

The comments you leave us are systematically subject to rigorous moderation. Incivility and slander, threats, intimidation of all kinds, more generally all gratuitous verbal violence, or the dissemination of unverified information... are not tolerated. We also reserve the right to publish only comments which effectively advance the debate and allow a better understanding of the subject covered by the article presented on this page (as well as all its ramifications) and this, whatever its overall content.

Image

Fond of Code TM © ®
All rights reserved - Protected Trademark/Logo (INPI)

Legal structures based in
Nice - FRANCE

Montreal - Canada
By appointment

SIRET: 41138921600028 (France)
Inc. : 661515-5 (Canada, Qc.)
Official resumption in France : March 2025
Beta version of the website : May 2024
Implementation : July 2024
Launch of initial activity : 1996 (Europe and North America)
New version of the website : April 2025

Fond of Code official launch : May 2025

Image
Image