php array flip value as key and make it simple -
i have been troubling format array correctly have code:
require('simple_html_dom.php'); $table = array(); $html = file_get_html('apc.html'); foreach($html->find('tr') $row) { $rack = ltrim($row->find('td',0)->plaintext); $location = ltrim($row->find('td',1)->plaintext); $usage = ltrim($row->find('td',2)->plaintext); $auk = ltrim($row->find('td',3)->plaintext); $cost = ltrim($row->find('td',4)->plaintext); $rack = rtrim($rack); $location = rtrim($location); $usage = rtrim($usage); $auk = rtrim($auk); $cost = rtrim($cost); $table[$rack][$usage][$auk][$cost] = true; } echo '<pre>'; print_r($table); echo '</pre>';
using simple_html_dom above can convert html table array follow:
[rack01] => array ( [741,60] => array ( [1.409,04] => array ( [267,72] => 1 ) ) [110,88] => array ( [210,67] => array ( [40,03] => 1 ) ) ) [rack 09] => array ( [843,84] => array ( [1.603,30] => array ( [304,63] => 1 ) ) )
i have result below:
array( [0] => array ( [usage] => 'rack 01', [usage] => '741,60', [auk] => '1.409.04', [cost] => '267,72') [1] => array ( [usage] => 'rack 02', [usage] => 'value???', [auk] => 'value???', [cost] => 'value???')
any apreaciate
something this. note trim
both left , right:
foreach($html->find('tr') $row) { $rack = trim($row->find('td',0)->plaintext); $location = trim($row->find('td',1)->plaintext); $usage = trim($row->find('td',2)->plaintext); $auk = trim($row->find('td',3)->plaintext); $cost = trim($row->find('td',4)->plaintext); $table[] = array('rack' => $rack, 'usage' => $usage, 'auk' => $auk, 'cost' => $cost); }
Comments
Post a Comment