hey there,
in Java, I can take a text file and build a two dimensional array out of it. I hope I can do that in PHP as well but I can't seem to be able to do it.
these are the specifics of my problem:
I have an xml file. for simplicity:
<person>
<name>john</name>
<last>smith</last>
</person>
<person>
<name>ana</name>
<last>smith</last>
</person>
I want to generate a two dimensional array, such that it's first row contains the array (<person>, <name>john</name>,<last>smith</last>, </person>) and it's second row contains (<person>, <name>ana</name>,<last>smith</last>, </person>)
what I tried is this:
//I use $end_delimit to know when to move to the next row of my two-dimensional array
function xmlToAray($file, $end_delimit){
$rez = array();
$lines = file($file);
$k = 0;//
$rows = array();
for($i = 0; $i < sizeOf($lines); $i++){
array_push($rows[$k], $lines[$i]);
if(strrpos($lines[$i],$end_delimit) === 0 || strrpos($lines[$i], $end_delimit) === 0){
$rez[$k] = $rows;
$k++;
}
}
return $rez;
}
what I get is a complaint: array_push() expects parameter 1 to be array, null given... I understand what this means, but I don't know how to avoid it. can you please tell me. thank you!