0% found this document useful (0 votes)
46 views

Source Code To PHP 2D-ARRAY

This document contains code examples demonstrating the use of PHP arrays and regular expressions. It includes code to: 1) Create a multi-dimensional array to store favorite indoor and outdoor games and loop through it to display the games. 2) Sort an array of games alphabetically before and after sorting. 3) Sort an associative array of books by price from highest to lowest. 4) Use regular expressions to find matches in strings and validate a password and email address.

Uploaded by

Malathi Sankar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Source Code To PHP 2D-ARRAY

This document contains code examples demonstrating the use of PHP arrays and regular expressions. It includes code to: 1) Create a multi-dimensional array to store favorite indoor and outdoor games and loop through it to display the games. 2) Sort an array of games alphabetically before and after sorting. 3) Sort an associative array of books by price from highest to lowest. 4) Use regular expressions to find matches in strings and validate a password and email address.

Uploaded by

Malathi Sankar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

// source code to PHP 2D-ARRAY

<html>

<body>

<?php

$favourate_games=array("indoor"=>array("carroms","chess","cards"),"outdoor"=>array("cricket","volly
ball","hockey"));

foreach($favourate_games as $category=>$games)

echo "<h3>my favourate" .$category. "games are:</h3>";

foreach($games as $game)

{ echo "<br>";

echo $game;

echo "<br>";

?>

</body>

</html>

// PROGRAM TO SORT ARRAY ELEMENTS

<?php

$games=array("Golf","cricket","Basket ball","volly ball","carraom","tennis");

print("<b> BEFORE SORTING</b>");

foreach($games as $game)

print "<BR>".$game;

sort($games);

print "<br><br>";
print("<b>AFTER SORTING</b>");

foreach($games as $game)

print "<BR>".$game;

?>

/*SORTING ASSOCIATIVE ARRAY U CAN CHECK ASORT,KSORT,RSORT,ARSORT,KRSORT WITH ALTERATION


OF SORT FUNCTION*/

<?php

$cse_books=array("java"=>800,"os"=>600,"php"=>650,"CN"=>400);

echo "<h3>BEFORE SORTING</h3>";

foreach($cse_books as $book_name=>$price)

echo "<br>".$book_name." ".$price;

arsort($cse_books);

echo "<h3>AFTER SORTING</h3>";

foreach($cse_books as $book_name=>$price)

print "<BR>".$book_name." ".$price;

?>

// REGULAR EXPRESSION PROGRAM IN PHP

<?php

if (preg_match("/ell/", "Hello World!", $matches)) {

echo "Match was found <br />";

echo $matches[0];

}
?>

// REGULAR EXPRESSION

<?php

if (preg_match("/ll.*/", "The History of Halloween", $matches)) {

echo "Match was found <br />";

echo $matches[0];

?>

// VALIDATION OF YOUR PASSWORD

<?php

$password = "Fyfjk34sdfjfsjq7";

if (preg_match("/^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/", $password)) {

echo "Your passwords is strong.";

} else {

echo "Your password is weak.";

?>

//VALIDATION OF YOUR EMAIL IN PHP

<?php

$email = [email protected];

$regexp = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";

if (preg_match($regexp, $email)) {

echo "Email address is valid.";


} else {

echo "Email address is <u>not</u> valid.";

?>

//

You might also like