I am receiving an array in php after making a request but the array doesn’t have a key value. Not sure if I need to parse or convert to an object first. Im using the simple_html_dom PHP library.
Here is the PHP script that grabs the table data from a website –
JavaScript
x
$table = array();
$html = file_get_html('www.mysite.com');
foreach($html->find('tr') as $row) {
$zero = $row->find('td',0)->plaintext;
$one = $row->find('td',1)->plaintext;
$table[$zero][$one] = true;
}
The Array I get as a response is structured like so –
JavaScript
Array(
[Model] => Array
(
[PA-31-310] => 1
)
[Year Manufacturer] => Array(
[1975] => 1
)
)
Ive tried parsing it like so but am not outputting any data –
JavaScript
foreach($table as $value){
$model = $value['Model'];
}
I feel like the array within the array is whats causing me issues, do I need to convert the array in order to get “Model”?
Advertisement
Answer
Change out the
JavaScript
$table[$zero][$one] = true;
for
JavaScript
$table[$zero] = $one;
This will make a simple key value array.