php arrays

Jan 11, 2016

Milan Sanathara

Php

1

php arrays

This blog will help you to understand the basic structure of an array and know how of an array with php array tutorial examples.

While,doing the programming ,so many times you need to create an array.So, what is an array exactly ? and why it requires?

What is an array?

In general, an array is a number of items arranged in some specified way.

An array is a data structure that contains a group of elements. Typically these elements are all of the same data type, such as an integer or string. Arrays are commonly used in computer programs to organize data so that a related set of values can be easily sorted or searched.

It works on the principle of key value combination.So that each value is stored in a specific cell with an unique key.

php arrays tutorial examples

php array tutorial examples

Consider, the above image, the array of programming languages, having keys 0,1,2,3,4 and each has some value ,such as php,java,C#.

The keys are unique identities of certain values.

Array In Php.

There are mainly three types of an array in php.

  • Numeric array
  • Associative array
  • Multidimensional array

Consider following php array tutorial examples.

Numeric Array

An array with a numeric index. Values are stored and accessed in linear fashion.

If you have an indexed array having key 0,1,2,3,4 then you can print any element with key.To get any certain out put,you need to write down following code.

You can also use the for loop to print the data from an array.

php arrays

php array

 Associative Array

Iteration of Array

Or , You can use the foreach loop.which returns with all printed elements of a given array.

php arrays

php array

Multidimensional Array

An array containing one or more arrays and values are accessed using multiple indices.

php arrays

php array

Iteration of Array

Now, consider if you have an multidimensional array as shown above,then you need to use foreach loop, To get data from an array.

Kindly,visit our blog regularly for learn more Slim Tutorial.
I hope you will find this post very useful regarding php and php arrays. Let me know any questions if you have in comment regarding php arrays. I will reply you ASAP.

Have you got cool idea about Web Development ? Contact us Now to get free consultation on your idea.  Alphanso Tech is rated as one of the best Php Development Company in India.

Post by Milan Sanathara

I am iOS Application Developer with an aspiration of learning new technology and creating a bright future in Information Technology.

One Response to php arrays

  1. Pingback: php tutorials with examples | Step by Step tutorial guide

Leave a Reply

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