4

Would anyone happen to know the PHP equivalent to C#'s datatable? I've considered (briefly) using a two-dimensional array, but consider it to be kind of dirty. Is there another data structure which might work for storing various types of data in a two-dimensional, row / column oriented (perhaps with headers?), easily-accessible fashion?

My other options is creating a DataTable structure for PHP, which I'd prefer to avoid, if at all possible.

user978122
  • 5,531
  • 7
  • 33
  • 41
  • what's a 2d array missing that you want? it would be relatively easy to create a class around a 2d array that has some helper methods for small things. – Scott M. Feb 20 '12 at 19:09
  • A clean way to access things, and set row headers / column headers. Maybe a few other things. If you play with .Net's DataTable, you'll know what I mean. Regular two-dimensional arrays are...primitive, and I'd like any future programmers to know, in a two words or less, what kind of data structure I used, as well as how to extend / play with it. – user978122 Feb 21 '12 at 00:08

3 Answers3

2

Maybe it will be helpful : Zend_DataGrid

Bartosz Grzybowski
  • 1,149
  • 8
  • 18
0

There are some eq. libs available as free/paid version. Following is the summary:

Example usage of phpgrid.org

$g = new jqgrid();
$g->table = "clients";
$out = $g->render("list1");
Azghanvi
  • 934
  • 10
  • 22
  • how to integrate phpgrid.org with Symfony 2 MVC – ahmed hamdy Dec 17 '13 at 14:26
  • first : i had made the same your write under Question `How can i integrate PHPGrid in MVC based frameworks like Yii, Codeignitor, Zend Framework, CakePHP and others.` But didn`t works. – ahmed hamdy Mar 10 '14 at 15:38
0

All of PHP's built-in types are much simpler than that.

Your best bet is to look in to an ORM library for PHP, which is where that type of functionality would be, if anyone has done it, but of course it would be very database oriented (kinda like DataTable is).

If all you want is rows, columns, and headers, then that's simple enough to roll your own -- maybe 30 to 40 lines of code or so. It'd probably be faster to make your own rather than find someone else's anyway.

Community
  • 1
  • 1
tylerl
  • 30,197
  • 13
  • 80
  • 113
  • Yeah, I'm beginning to think that way be what I want to do. It just requires more time. Tell me, does PHP support operator overloading? Is it trivial? – user978122 Feb 21 '12 at 00:09
  • maybe trying to shoehorn .net into php isn't what you want to do. Operator overloading isn't supported except for some array features. you can have a look at http://php.net/manual/en/class.arrayaccess.php to see array access overloading, but that's as far as you'll get. – Scott M. Feb 21 '12 at 13:32