PHP – Echo content

PHP – Echo content

 

PHP has basically two ways of sending content to the browser and those are echo and print. The difference is that print returns a value of 1 when execute while echo doesn’t return anything. Another difference is that em>print accepts only one argument while echo accepts a list of arguments (as many as you like). In PHP we normally use echo to output content while print it left aside for rare and very specific situations.

Echo can be both used with or without parenthesis: echo and echo() are equivalents. According to the PHP manual “echo is not actually a function, it is a language construct”

PHP

<?php 
$a = "Hello";
$b = "John Doe";
$x = 1;
$y = 2;

echo "Hello World"; // echoes Hello World
echo "$a $b"; 	// echoes Hello John Doe
echo $a.' '.$b.', how are you today?'; // echoes Hello John Doe, how are you today?
echo $x + $y; // echoes 3
?>

Using single o double quotes when echoing

Did you note the quotation mark used to echo? We used both the double quotes and single quotes. The difference is that single quotes will print the variable name, and double quotes will print the value

PHP

<?php 
$no = "12";

echo "Lucky number $no <br/>"; // echoes Lucky number 12
echo 'Lucky number $no'; // echoes Lucky number $no
?>

Shorthand echo – Write code faster

Echo has a syntax shortcut so you can easily insert it into your HTML content.

PHP

<?php 
$no = "12";
?>

<p>Lucky number <?=$no?></p>

Prior to PHP 5.4.0, You will need to have the short_open_tag enabled in order to work

The PHP print function

Similar to echo, the print function can be used both with parenthesis or without them.

PHP

<?php 
$a = "Hello";
$b = "John Doe";
$c = "World";

print($c); // prints Hello World
print "$a $b"; 	// prints Hello John Doe
print $a.' '.$b.', how are you today?'; // prints Hello John Doe, how are you today?
?>

Go ahead and practice a little bit with the PHP echo statement. This is one of the fundamental functions when you start working with PHP. It allows you to build dynamic expressions that will adapt to different situations.

 

Python Example for Beginners

Two Machine Learning Fields

There are two sides to machine learning:

  • Practical Machine Learning:This is about querying databases, cleaning data, writing scripts to transform data and gluing algorithm and libraries together and writing custom code to squeeze reliable answers from data to satisfy difficult and ill defined questions. It’s the mess of reality.
  • Theoretical Machine Learning: This is about math and abstraction and idealized scenarios and limits and beauty and informing what is possible. It is a whole lot neater and cleaner and removed from the mess of reality.

Data Science Resources: Data Science Recipes and Applied Machine Learning Recipes

Introduction to Applied Machine Learning & Data Science for Beginners, Business Analysts, Students, Researchers and Freelancers with Python & R Codes @ Western Australian Center for Applied Machine Learning & Data Science (WACAMLDS) !!!

Latest end-to-end Learn by Coding Recipes in Project-Based Learning:

Applied Statistics with R for Beginners and Business Professionals

Data Science and Machine Learning Projects in Python: Tabular Data Analytics

Data Science and Machine Learning Projects in R: Tabular Data Analytics

Python Machine Learning & Data Science Recipes: Learn by Coding

R Machine Learning & Data Science Recipes: Learn by Coding

Comparing Different Machine Learning Algorithms in Python for Classification (FREE)

Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.  

Google –> SETScholars