1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

matrix addition in php

Discussion in 'PHP' started by hulkrana, May 24, 2007.

  1. #1
    helo frds
    i am new in php .please tel me how to perform matrix additon
    <?php
    echo "enter the number";
    for(int i=0;int i<=2;int i++)
    {
    for(int j=0;int j<=2;int j++)
    {
    echo "enter the number" $a[j];
    }
    echo "\n";
    }
    ?>
    here i am not getting how to get the matrin values


    thanks

     
    hulkrana, May 24, 2007 IP
  2. tinkerbox

    tinkerbox Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Should be like this
    
    for($i=0;$i<=2;$i++)
    {
    for($j=0;$j<=2;$j++)
    {
    echo "enter the number $i$j<br>";
    }
    } 
    
    Code (markup):
     
    tinkerbox, May 24, 2007 IP
  3. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #3
    php is a web scripting language not desktop/console.try this type of things in C/C++/JAVA
     
    coderbari, May 24, 2007 IP
  4. zzzttt

    zzzttt Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    make an html form, or get the data from a database ... you need to be more explicit.
     
    zzzttt, May 24, 2007 IP
  5. cjramki

    cjramki Greenhorn

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #5
    You cant get the input directly from the user like c,c++ or java...

    You should get the user input using html form controls...
    <form action="" method="post">
    Enter the value : <input type="text" name="input">

    You can get from the PHP like this
    <?php
    $input=$_POST['input'];
     
    cjramki, Aug 5, 2013 IP
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    Should work fine on console (which I assume you are using since you original code was using \n for newlines):

    
    <?php
    $matrix = array();
    for ($i=0; $i <= 2; $i++) {
        for ($j=0; $j <= 2; $j++) {
            echo PHP_EOL . "Enter the number for [$i][$j]:";
            $line = fgets(STDIN);
            $matrix[$i][$j] = trim($line);
        }
    }
    
    Code (markup):
     
    ThePHPMaster, Aug 5, 2013 IP