Created
February 13, 2014 09:51
-
-
Save ChaosPower/8972455 to your computer and use it in GitHub Desktop.
PHP: Vertical Matrix Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* Utility class for matrix vertical data | |
* | |
* @author ChaosPower | |
* @license WTFPL | |
* | |
*/ | |
class matrixGen { | |
public static function getModel($arr = array()) | |
{ | |
// model example | |
// $arr = array( | |
// 'dbTable' => (object) array( | |
// 'col' => array( //Database Tables 1:1 | |
// 'x','x2','x3','x4','','2' | |
// ), | |
// ), | |
// 'dbTable2' => (object) array( | |
// 'col' => array( //Database Tables 1:1 | |
// 'y','y2','y3','y4' | |
// ), | |
// ), | |
// 'dbTable3' => (object) array( | |
// 'col' => array( //Database Tables 1:1 | |
// 'z','z2','z3','z4','','','x' | |
// ), | |
// ), | |
// 'dbTable4' => (object) array( | |
// 'col' => array( //Database Tables 1:1 | |
// 'a','a2','a3','a4', 'a4','a4','a4','a4' | |
// ), | |
// ), | |
// ); | |
return ($arr) ? (object) $arr : false; | |
} | |
public static function matrix() | |
{ | |
if(formXHelper::getModel()){ | |
$cols = 0; | |
foreach(formXHelper::getModel() as $key => $value) | |
{ | |
if(count($value->col) > $cols) | |
{ | |
$cols = count($value->col); | |
} | |
} | |
for($i = 0; $i < $cols; $i++) | |
{ | |
$arrx[$i] = new stdClass(); | |
$arrx[$i]->{x} = $i; | |
foreach(formXHelper::getModel() as $key => $val) | |
{ | |
$arrx[$i]->{$key} = formXHelper::getModel()->{$key}->col[$i]; | |
} | |
} | |
return $arrx; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment