Multi Dimensional arrays in php programming languages. Multi Dimensional 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):-
Multi Dimensional Arrays |
<?php $food = array('Healthy'=>array ('salad',Vegetables','Pasta'); 'Unhealthy'=>array('Pizza','ice cream')); echo $food['Healty'][1]; ?>
Output (Screenshot2) :-
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
Unhealthy
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):-
Screenshot3 |
<?php $food = array('Healthy'=>array ('salad',Vegetables','Pasta'); 'Unhealthy'=>array('Pizza','ice cream')); echo $food['Unhealty'][1]; ?>
Output (Screenshot4):-
Screenshot4 |
No comments:
Post a Comment
Thanks For Comment Will get you Soon..