
簡單測試memcache的code
1
2
3
4
5
6
7
8
9
10
11
12
|
<?php
$memcache = new Memcache; //Star memcache
$memcache->connect('localhost', 11211) or die ("Could not connect"); //Connect Memcached
$memcache->set('uname', 'appleboy');
$get_value = $memcache->get('uname'); //
echo $get_value;
print "<br/>";
$b = $memcache->getStats();
print_r($b);exit;
$memcache->delete('uname'); //刪除key
?>
|
測試nesting array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<?php
$tmpArray = array(
array("one", array(1, 2, 3)),
array("two", array(4, 5, 6)),
array("three", array(7, 8, 9))
);
// Scan through outer loop
foreach ($tmpArray as $inner) {
// Check type
if (is_array($inner)) {
// Scan through inner loop
foreach ($inner[1] as $value) {
echo "$value n";
}
}
}
?>
//out put 123456789
|
參考PHP foreach with Nested Array?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
<?php
private function _build_hiiir_excel ($contentList, $titleList)
{
foreach ($contentList as $i => $content)
{
$city_code = $this->config->item('city_code');
$status = Store::$allStatus;
$j = 0;
foreach ($titleList as $title => $exp)
{
if ($i == 0)
{
$this->hiiir_excel->getActiveSheet ()->getStyle (chr (65 + $j) . ($i + 1))->getAlignment ()->setVertical (PHPExcel_Style_Alignment::VERTICAL_CENTER);
$this->hiiir_excel->getActiveSheet ()->getStyle (chr (65 + $j) . ($i + 1))->getFont ()->setName ('新細明體');
$this->hiiir_excel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$this->hiiir_excel->getActiveSheet ()->SetCellValue (chr (65 + $j) . ($i + 1), $title);
}
eval ('$val = ' . $exp . ';');
$this->hiiir_excel->getActiveSheet()->getStyle(chr (65 + $j) . ($i + 2))->getAlignment ()->setVertical (PHPExcel_Style_Alignment::VERTICAL_CENTER);
$this->hiiir_excel->getActiveSheet()->getStyle(chr (65 + $j) . ($i + 2))->getFont ()->setName ("新細明體");
//增加自動調整欄位長度於欄位A
$this->hiiir_excel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$this->hiiir_excel->getActiveSheet()->SetCellValue(chr (65 + $j) . ($i + 2), $val);
$j++;
}
}
}
?>
|
如果想要從A~F的欄位都要,就要loop:
1
2
3
4
5
6
7
8
9
10
11
12
|
<?php
for($col = 'A'; $col !== 'G'; $col++) {
$objPHPExcel->getActiveSheet()
->getColumnDimension($col)
->setAutoSize(true);
}
//或是用foreach
$nCols = 6; //set the number of columns
foreach (range(0, $nCols) as $col) {
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setAutoSize(true);
}
?>
|
參考這篇[Setting autosize column phpExcel]http://stackoverflow.com/questions/21286275/setting-autosize-column-phpexce
近期评论