hi everyone this is Raghu from Eldred calm and welcome to PHP video series in this lecture we will see foreach loop so let’s open our editor so let’s create a new file in servitors for each dot PHP don’t forget to add the extension dot PHP so first of all what is foreach loop and how it is different different from for loop so this foreach is a special type of loop it is used in case of arrays and it is used to loop through the elements of arrays so let’s start coding okay the PHP tag and then inside the tag so let’s create an array so if you don’t have I know definitely if you are a beginner you don’t have how to create arrays and how to use arrays and water arrays so remember for now array is nothing but a group of variables it’s like we can store see for example I have variable a and variable B and variable C so in all the three variables I want to store different different values but I don’t want to use multiple variables so instead of that we can use a simple array and inside the array we can store all these values and we can access those values with their index it’s like if I use a of 0 it will print 1 if I use a of one we will print 2 similarly so this is called index so this 0 1 2 these are called index and this is called the value okay so don’t worry in the future lectures we will definitely cover arrays in PHP but for now let’s see so this is how we will create the arrays so ARR this is our array name equals array off so let me give some values 10 20 30 and 40 and then 50 this is my array so I want to print all these elements so I can use for each okay this is the syntax and we we just need this is the syntax for for each loop then here the variable is nothing but our array so for each dollar array as value so here every time this variable value will have the the current iterator are the index value so let me print it so use break the element in the array is dot dollar value that’s all we need so let’s save and open our browser so let’s open foreach loop okay there is something wrong with line three that is okay all right this is no small typo let’s reload what is wrong with this okay here I have to use sorry for the typos okay so I got all these elements so this is how we can use for each loop so let me explain why do we need a for each loop so let me take the same example how can I achieve the same functionality by using just the for loop so let’s create the farlow so here let me have the iterator as I and initialized with zero because as I mentioned our array index will start with zero and then till what point we have to loop we don’t know the size so we need to find the size so we can get that by using count off alright that is taller all right there we are incrementing and similarly we can do this Eko element in the array ease so how can we print the alright top exact index value so 1 array within these braces are square braces we can have taller I let’s say and open our browser so if you see this is our for each loop and we got this output with our for loop so that’s why we can interchange Li use all these loops

Tags:






Youtube
Facebook
Google Plus
Twitter
TutorialDrive


Apache Zookeeper Tutorial

Apache Kafka Tutorial

Apache Kafka Security

Elasticserarch n Kibana

Java 8 Tutorial

Log4J Tutorial

Apache Storm Tutorial

SQLite Tutorial

Apache Ant Tutorial

Related Posts

blog

Apache Kafka Commands Cheat sheet

Spread the loveKafka Topics List existing topics bin/kafka-topics.sh –zookeeper localhost:2181 –list Purge a topic bin/kafka-topics.sh –zookeeper localhost:2181 –alter –topic mytopic –config retention.ms=1000 … wait a minute … bin/kafka-topics.sh –zookeeper localhost:2181 –alter –topic mytopic –delete-config retention.ms
Read more…

blog

What is Apache Maven | Apache Maven complete tutorial from scratch pdf

Spread the love In this post you will learn the complete tutorial of Apache Maven build tool What is Maven ? Apache Maven is a software project management and comprehension tool. Based on the concept
Read more…

blog

Practical Guide for Web Development in 2018

Spread the loveWelcome to my practical guide  for web development in 2018 in terms of  technology and career. Before we start I just want to  mention a few things, you don’t need to learn  everything that
Read more…