Jump to content

creating matrix from list of data


shane8514

Recommended Posts

Hello,

I'm sorry if this seems like a basic question, but I've been pulling my hair out trying to figure this out.  I'm an infrequent PHPer at best, and that makes even simple stuff difficult.  Accordingly, I don't have any code to offer up to you all.

I have a list of values for each state... it looks like this

state1: .5
state2: .4
state3: .7

I want to go through and calculate absolute differences and plop those into a matrix (I have managed to already create that).

So it should look like this:

            state1    state2   state3
state1    0               .1          .2
state2     .1              0          .3
state3      .2              .3          0

Try as I might I'm coming up short on how to do this....  can you think of an easy code to do it offhand?


Thanks!
Shane

Link to comment
https://forums.phpfreaks.com/topic/275237-creating-matrix-from-list-of-data/
Share on other sites

$state=Array (.5,.3,.7);
foreach ($state as $key => $value) {
    echo $key." ";
    foreach ($state as $key1 => $value1){
        $diff= $value-$value1;
        echo $diff." ";
    }
    echo "<br />\n";  
}

You'll need to add a bit of formatting but it seems to work as a nested loop.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.