Php – Array Variable Type

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/php-array-variable-type/
PINTEREST
PINTEREST
INSTAGRAM

PHP Tutorial Topics

  1. Introduction To PHP
  2. Installing PHP To Linux
  3. Installing PHP To Windows
  4. PHP Hello World Project with Eclipse
  5. PHP Syntax
  6. PHP Variables and Types
  7. PHP String Types
  8. PHP Numeric Type (Integer, Float, Double)
  9. PHP Boolean Type
  10. PHP Arrays
  11. PHP Operators
  12. PHP Ternary Operators
  13. PHP Constants
  14. PHP If..Elseif..Else Conditional Statements
  15. PHP Switch..Case Conditional Statements
  16. PHP For and Foreach Loop Statements
  17. PHP While and Do While Statements
  18. PHP Functions
  19. PHP Class and Objects
  20. PHP Date and Time Operations

We have used single value variable types up to now. But the real world problems may need different solutions and variables then those. We generally define,use multiple and a lot of values. Defining one by one variable is not a practical solution for these situations.

For example we want to store 5 students names in a single variable. We call these as arrays. Arrays can hold multiple values.

Define Array

Arrays can be defined in different ways. One of them is just providing the type as array. This will not put any data into array. In this example we will create a array named $students .

We can also define an array just initializing or giving values like below.

Initialize Array

We programmers generally use most faster way of defining and initializing an array. We will simply provide the array elements in square brackets by separating them with command. In this example we will define array named $students and put students names elements.

This type of array definition and initialization is same as like below.

LEARN MORE  Different Ways To Use Python Print Function

Index Numbers

As you see we are using numbers to specify array index. Index is used to specifically specify an element in array. Index numbers starts from  by default. This means default array with 4 element index numbers starts from  and up to 3 . We can access array elements by giving index number. Index numbers are specified in square brackets.

In the following example we will change the element which index numbers is 1 .

Associative Arrays

We have used index numbers to specify specific elements in previous part. Array have another usage for specifying elements in array. It is called associative . We can set strings to specify index numbers like names. In this example we will use students names as array element specifier.

And we can access associative arrays by specifying string. We will get ismail age from associative array.

Multidimensional Arrays

We have use single dimension arrays up to now. We can also use array inside array. These type of arrays called multidimensional arrays. There is no restriction about the level of dimensions. In the following example we will define an array which holds student information arrays inside it.

We can access the inner arrays elements and values by using square brackets.

LEARN MORE  Linux Bash Arrays and Elements

Print Arrays

Printing whole array is one of the most used function and debug operation while developing applications. We can print whole array with the print_r() function by providing the array. We will print array named $student in the following example.

Print Arrays

Print Arrays

PHP Tutorial Topics

  1. Introduction To PHP
  2. Installing PHP To Linux
  3. Installing PHP To Windows
  4. PHP Hello World Project with Eclipse
  5. PHP Syntax
  6. PHP Variables and Types
  7. PHP String Types
  8. PHP Numeric Type (Integer, Float, Double)
  9. PHP Boolean Type
  10. PHP Arrays
  11. PHP Operators
  12. PHP Ternary Operators
  13. PHP Constants
  14. PHP If..Elseif..Else Conditional Statements
  15. PHP Switch..Case Conditional Statements
  16. PHP For and Foreach Loop Statements
  17. PHP While and Do While Statements
  18. PHP Functions
  19. PHP Class and Objects
  20. PHP Date and Time Operations
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/php-array-variable-type/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)