php, get values from matrix (array)
I have Matrix开发者_Python百科 and how get value from there? The data obtained from a file, so that the matrix can be of different sizes
Thanks
Hypothetically (because the question is vague), if you read the contents in and have the results stored in a two-dimensional array, then you would use brackets to find the cell value. For example, here's reading in the contents into a multidimensional array called $matrix:
$contents = file_get_contents("myfile.csv");
$splitlines = explode("\n",$contents);//split the contents into rows
$matrix = array();
foreach($splitlines as $line){
$row = explode(",",$line);//split each line into columns
$matrix[] = $row;//add the array of columns as a new row in the matrix
}
now address any of the values in the matrix:
$samplevalue = $matrix[2][1]; //addresses the third row, second column.
精彩评论