Variables in PHP

Variables – PHP

Variables are used to store data and can be called by using the variable name and the data that it holds will be outputted instead.

For example, I want to save the message “Hello Hirdesh” in memory and then first display hello Hirdesh and afterward Welcome to PHP World, I will write the following simple programme

// Example of concatenate string.

<?php
$text = “Hello Hirdesh”;
echo  $text.”Welcome to PHP World”;
?>

Please Note that dot (.) operator is used to concatenate or combine string in php

 

Naming Conventions

  •     Variable name start with the dollar sign
  •     Must contain only letters, numbers, and the underscore sign
  • Cannot start with a numeric value
  • Variable name are case sensitive

To minimize confusion and errors, it’s best to stick to one naming scheme. The two most common styles are

Use all lowercase, separating words with underscores: $first_name, $emp_code, etc.

Use primarily lowercase, separating words with capital letters: $textName, $fName, etc.

 

Assigning Values

Variables can be assigned using the assignment operator (=). Some examples are below-

$status = false;

$empCode = 231;

$average = 86.67;

$name = “Jyoti”;

$con = mysqli_connect(‘localhost’, root’, ”, ‘mydb’);

$key = NULL;

Object variables are assigned using the assignment operator with the new keyword:

$ob = new myClass();

 

Example – calculate sum of 2 numbers using variables

<?php
// program to calculate sum of two numbers

$num1 =20;

$num2=30;

$sum=$num1+$num2;

echo  “Sum is ”.$sum;
?>

Example – define function

<?php

define(“tutorial”,”Programing Logic and Technique”);

echo constant(“tutorial”);

?>

Output : Programming Logic and Technique

 

To Buy complete book kindly download – php mysql for advanced learning from amazon, flipkart, google playstore and many more channels.

Leave a Reply

Your email address will not be published. Required fields are marked *

About Us

Luckily friends do ashamed to do suppose. Tried meant mr smile so. Exquisite behaviour as to middleton perfectly. Chicken no wishing waiting am. Say concerns dwelling graceful.

Services

Most Recent Posts

  • All Post
  • advanced-excel-training
  • Branding
  • deepti saini model
  • Development
  • Digital Marketing
  • digital marketing course gurgaon
  • Digital Marketing Internship Gurugram
  • digital marketing jobs
  • digital-marketing-institutes-sector-14
  • Leadership
  • Management
  • Notice
  • php-development-courses
  • php-full-stack-development-courses
  • php-job-opportunity
  • php-training
  • php-training-in-baksar
  • php-training-in-balia
  • php-training-in-bangalore
  • php-training-in-delhi
  • php-training-in-faridabad
  • php-training-in-gaziabad
  • php-training-in-gorakhpur
  • php-training-in-gurgaon
  • php-training-in-kolkata
  • php-training-in-muzaffarpur
  • php-training-in-noida
  • php-training-in-patna
  • placements
  • web development training gurgaon
  • web-development-course-in-sector-14

Company Info

She wholly fat who window extent either formal. Removing welcomed.

Limited Seats Available – Register Now

We keep batch sizes limited so every learner gets personal attention and proper doubt solving. Reserve your seat now and start your training in the next batch without delay. For details call us +91- 8802000175

Help

Privacy Policy

Terms

Conditions

Subscribe Now

For latest news and updates, fill your details below-

You have been successfully Subscribed! Ops! Something went wrong, please try again.
© 2023 Created with Royal Elementor Addons