grissom Posted July 19, 2015 Share Posted July 19, 2015 (edited) Hi guys. This one should be really simple but I've got a mental block on it and would really appreciate some help. I'm using some classes from an existing open source class EZPDF to format a table, and their syntax for doing so is like this (here's an example .. here we take an array called $data with fields 'Date', 'Name' and 'Postcode' and assign widths to the columns) $pdf->ezTable($data,'','',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1, 'cols'=>array('Date'=>array('width'=>120), 'Name'=>array('width'=>100), 'Postcode'=>array('width'=>80)) )); Well, that looked a little bit too much work for my lazy brain, so I decided to extend the class and write a new function which basically read in all the data keys and matched them to an array of widths and then did the same thing. But with more convenient shorthand for me ! So here's how I approached it : function basictableformat($data, $widthsarray) { $basicarray = array(); $i = 0; foreach ($data[0] as $key=>$value) { $widthbit = array('width'=>$widthsarray[$i]); $basicarray[$key] = $widthbit; $i++; } $this->ezTable($data,'','',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1, 'cols'=>array( $basicarray ) )); } However, as you can guess .. this didn't work ! It should be EASY but I've just got a Sunday morning mental block on it. Any help folks is massively appreciated. Edited July 19, 2015 by grissom Quote Link to comment https://forums.phpfreaks.com/topic/297362-array-within-an-array-within-an-array/ Share on other sites More sharing options...
Ch0cu3r Posted July 19, 2015 Share Posted July 19, 2015 Whats your question/problem? Quote Link to comment https://forums.phpfreaks.com/topic/297362-array-within-an-array-within-an-array/#findComment-1516750 Share on other sites More sharing options...
Solution grissom Posted July 19, 2015 Author Solution Share Posted July 19, 2015 The problem is that although no errors are being thrown up, the table is not formatting with the column widths I am specifying As a bit of extra info, here's an example of how I would set up and call the function $data = array(); $data[] = array('Date'=>'12-12-2015', 'Name'=>'Alice', 'Postcode'=>'HG1'); $data[] = array('Date'=>'25-11-2015', 'Name'=>'Bob', 'Postcode'=>'SE2'); $widths = array(100, 120, 60); basictableformat($data, $widths); Quote Link to comment https://forums.phpfreaks.com/topic/297362-array-within-an-array-within-an-array/#findComment-1516751 Share on other sites More sharing options...
grissom Posted July 19, 2015 Author Share Posted July 19, 2015 Solved it folks ! I had the line 'cols'=array($basicarray) and of course $basicarray already WAS an array ! so it should have been just 'cols'=$basicarray Quote Link to comment https://forums.phpfreaks.com/topic/297362-array-within-an-array-within-an-array/#findComment-1516761 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.