| Multi Dimensional Arrays in php |
Multi Dimensional arrays in php programming languages. MultiDimensional Arrays are very important to use into practice when we use arrays. Now as created associative arrays with different food types and we assign values of amount of calories in each food. Now we move on to Complicated and more excited which is multi dimensional arrays. Basic Concepts of multi dimensional is array inside an array and this can be multi dimensional so, Its can be two dimensional array three dimensional array and so on. You need to think about this as categories.
Code For Multi Dimensional arrays (Screenshot1):-
1
2
3
4
5
6
| <?php$food = array('Healthy'=>array ('salad',Vegetables','Pasta');'Unhealthy'=>array('Pizza','ice cream'));echo $food['Healty'][1];?> |
Output (Screenshot2) :-
In this example i am going to creating two categories like Healthy which contains healthy food and unhealthy category which contains unhealthy food
Healthy
Salad
Vegetable
Pasta
Salad
Vegetable
Pasta
Unhealthy
Pizza
Icecream
Pizza
Icecream
So, as you see example we had created array inside an array. And how we can use elements of array inside array for that we address a array Healthy in square brackets and key of array which is inside array such as [0]. Which will addresses to the salad.
Code for Multi dimensional arrays(Screenshot3):-
1
2
3
4
5
6
| <?php$food = array('Healthy'=>array ('salad',Vegetables','Pasta');'Unhealthy'=>array('Pizza','ice cream'));echo $food['Unhealty'][1];?> |
Output (Screenshot4):-
In this example i am addresses Ice cream of unhealthy food as you seen example hope have idea of multi dimensional arrays and how we can use it in practice. Its Multi dimensional arrays in php programming languages.
Read More Extra Tutorials
No comments:
Post a Comment