shane8514 Posted March 4, 2013 Share Posted March 4, 2013 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 thisstate1: .5state2: .4state3: .7I 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 state3state1 0 .1 .2state2 .1 0 .3state3 .2 .3 0Try 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 More sharing options...
davidannis Posted March 4, 2013 Share Posted March 4, 2013 $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. Link to comment https://forums.phpfreaks.com/topic/275237-creating-matrix-from-list-of-data/#findComment-1416531 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.