Implementing variables and arrays in php

0
1312

In this session today we will learn to implement variable and arrays in php.

  • To study the implementation of arrays and variables in php follow the steps given below :

  1. Install the xampp server , if it is installed already then go to the Xampp folder c:Xampp
  2. v1

  3. Inside this Xampp folder you will find an htdocs folder
  4. In this htdocs folder create a new folder say s3.
  5. v2

  6. In s3 folder create an index.php file and open it with notepad++.
  7. v4

  8. So now let’s learn to declare a variable , write the following code in index.php file
  9. You will have the following look of your notepad++ window :
  10. v5

  11. To run the program , open up the browser and enter the following url in the address bar : http://localhost/s3/index.php

    Note: Here s3 is the folder name in the htdoc ,
    index.php is the file name inside the s3 folder.
  12. Hence you will have the following output :
  13. v6

  14. Let’s have an example for concatenation ,so create a new index1.php file and write the following code in it:
  15. Now to have the output enter the url in the address bar : http://localhost/s3/index1.php
  16. Hence you will have the output which will have concatenation implemented in it
  17. v7

  18. Now lets take an example which will include the implementation of variable and array in php.
  19. So in s3 folder create a new file say complete.php and write the following code in it :
  20. You will have the following view of your notepad++ window :
  21. 1
    2

  22. Now to run the php program , open up the browser and enter the following url :
    http://localhost/s3/complete.php
  23. Hence you will have the output as shown below :
  24. 3

  25. Lets code to get the array element using foreach loop.
  26. So create a new file say foreach.php in s3 folder and write the given code in it :
  27. Now run the program by entering the address in the browser as http://localhost/s3/foreach.php
  28. So you will have the following output :
  29. v11

  30. Let’s have an example of associative array , so create a new file in s3 folder say associative.php and write the following code in it:-
  31. Now run the program by entering the address in the browser as http://localhost/s3/associative.php
  32. Hence you will have the following output :
  33. v12

  34. Thus we had a brief discussion on implementation of variables and arrays in php.

LEAVE A REPLY

Please enter your comment!
Please enter your name here