Skip to main content

Generate Sprial matrix In Php


Generate Sprial matrix In Php



<html>
<head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js"></script>    
<script>
$(document).ready(function (){
    spiralArray = function (edge) {
    var arr = Array(edge),
        x = 0, y = edge,
        total = edge * edge--,
        dx = 1, dy = 0,
        i = 0, j = 0;
    while (y) arr[--y] = [];
    while (i < total) {
        arr[y][x] = i++;
        x += dx; y += dy;
        if (++j == edge) {
            if (dy < 0) {x++; y++; edge -= 2}
            j = dx; dx = -dy; dy = j; j = 0;
       }
    }
    return arr;
}

// T E S T:
arr = spiralArray(edge = 5);
for (y= 0; y < edge; y++)
{
    console.log(arr[y].join(" "));

}
   
});
</script>
</head>
<body>
<p></p>
</body>
</html>

Comments

Popular posts from this blog

$var = 'PHP Tutorial'. Put this variable into the title section, h3 tag and as an anchor text within a HTML document.

$var = 'PHP Tutorial'. Put this variable into the title section, h3 tag and as an anchor text within a HTML document.  <?php echo "<html>"; echo "<head>"; echo "<title>"; echo "PHP TUTORIAl"; echo "</title>"; echo "<body>"; echo "<h3>PHP TUTORIAL</h3>"; echo "<hr>"; echo "<p>PHP, an acronym for Hypertext Preprocessor, is a widely-used open source general-purpose scripting language. It is a cross-platform, HTML embedded server-side scripting language and is especially suited for web development.</p>"; echo "</body>"; echo "</head>"; echo "</html>"; ?> Output:

Create a simple HTML form and accept the user name and display the name through PHP echo statement.

Create a simple HTML form and accept the user name and display the name through PHP echo statement. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Post Data</title> </head> <body> <form method="POST" action=""> <label>Enter First Name</label> <input type="text" name="firstname" id="firstname" /> <input type="submit" name="submit_button" value="Submit Name" /> </form> </body> </html> <?php if(isset($_POST) && !empty($_POST)) { echo "<h3> Hello ".$_POST['firstname']."</h3>"; } ?> Output:

Write a PHP script, which change the color of first character of a word.

Write a PHP script, which change the color of first character of a word. <?php   $text = 'PHP Tutorial';   $text = preg_replace('/(\b[a-z])/i','<span style="color:red;">\1</span>',$text);   echo $text;   ?>