Skip to content

Instantly share code, notes, and snippets.

@ChaosPower
Created February 13, 2014 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChaosPower/8972455 to your computer and use it in GitHub Desktop.
Save ChaosPower/8972455 to your computer and use it in GitHub Desktop.
PHP: Vertical Matrix Example
<?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