Writing PHP Array Function
PHP array : array can store multiple values in it, below
are different scenarios are given
to understand how to write array,
Scenario1
<html>
<body>
<title> Writing PHP Array Function </title>
<?php
$fruit = array("Mango","Apple","Banana","Kiwi");
var_dump($fruit);
?>
</body>
</html>
Output :
array(4) { [0]=> string(6) "Mango" [1]=> string(4)
"Apple" [2]=> string(5) "Banana" [0]=> string(3)
"Kiwi" }
scenario2
<html>
<body>
<title> Writing PHP Array Function </title>
<?php
$fruit = array("Mango","Apple","Banana","Kiwi");
print_r($fruit);
?>
</body>
</html>
Output :
array(4) { [0]=> string(6) "Mango" [1]=> string(4)
"Apple" [2]=> string(5) "Banana" [0]=> string(3)
"Kiwi" }
scenario3
<html>
<body>
<?php
/* First Scenario to create
array. */
$numbers = array( 55, 66, 77, 88, 99);
foreach( $numbers as $value ) {
echo "Value is $value
<br />";
}
?>
</body>
</html>
Output :
Value is 55
Value is 66
Value is 77
Value is 88
Value is 99
Scenario4
<html>
<body>
<?php
/* Second Scenario
to create array and assign values to it. */
$fruit[0] = "mango one";
$fruit[1] = "banana
two";
$fruit[2] = "apple
three";
$fruit[3] = "kiwi four";
$fruit[4] = "greps
five";
foreach( $numbers as $value ) {
echo "Fruit value is $value
<br />";
}
?>
</body>
</html>
Output :
Fruit value is mango one
Fruit value is banana two
Fruit value is apple three
Fruit value is kiwi four
Fruit value is greps five
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a comment