filmov
tv
Creating Array in PHP using Key & values and displaying elements by index position and by looping

Показать описание
We can create arrays in PHP by using data. Usually multiple data of similar types are stored in single array variable.
There are three types of arrays in PHP. Numeric or index array where all keys are incremental numeric starting from 0, second type were we assign keys or indexes to the array element. We call this type as Associative arrays
We can create one array by declaring as Array().
$my_data = array('mydata1','mydata2','mydata3', 'Mydata');
Here index position starts from 0 and second position is 1 and goes on
We can create one associative array by using key value pairs.
We can get total number of elements present in an array by using sizeof() function.
We can also create an array by using explode() function. This function uses one delimiter to break as string to create an array.
Using range() function we can create array. This function takes one start value and one end value, one optional value of step we can also provide. This will return an array using these values.
print_r() displays key with value of any array in human readable format.
#phpcreatingarray #arraycreating #displayingarray