Blog Introductions
In this blog contains tutorials about HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials, Examples, Source code,Learning,
Tips and Software development services. Php Arrays and its work | Php tutorials Bestitworrior
Php Arrays and its work
Php Arrays and its work | Php tutorials Bestitworrior - Arrays are the variable which hold multiple values in one array variable . IF we need to store 10 value in varible then we need to declear 10 variables and then store 10 values in each of them .This is the problem in time consuming to saving time and less effort then we use array one variable to hold all of 10 values.Now array save time and lines of code .Array is easy to iterate sort and munipulate and perform various function on data.
Some Key Points of PHP Arrays
- Array hold multiple values in one variable
- Easy to code array rather the having multiple variables
- Array can sort values
- We can use loop to access array values
- Arrays same time and lines of code
- We can delete or add new values from array
- We can modefy array values
- Index array use to access by index
- Associative array use to access by key
Code
<?php
echo "Index Array Output<br>";
$month = array("january", "feburary", "march");
echo "Months : " . $month[0] . ", " . $month[1] . " and " . $month[2] . ".";
echo "<br>";
$month1 = array("january", "feburary", "march");
$length = count($month1);
for($i = 0; $i < $length; $i++) {
echo $month1[$i];
echo "<br>";
}
echo "<br>";
echo "Associative Arrays<br>";
$month2 = array("Jnauary"=>"1", "Feburary"=>"2", "March"=>"3");
echo "January month number - " . $month2['Jnauary'];
echo "<br>";
$month3 = array("Jnauary"=>"1", "Feburary"=>"2", "March"=>"3");
foreach($month3 as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
OutPut
Index Array Output
Months : january, feburary and march.
january
feburary
march
Associative Arrays
January month number - 1
Key=Jnauary, Value=1
Key=Feburary, Value=2
Key=March, Value=3
Months : january, feburary and march.
january
feburary
march
Associative Arrays
January month number - 1
Key=Jnauary, Value=1
Key=Feburary, Value=2
Key=March, Value=3
0 Comments