Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.