开发者

php, get values from matrix (array)

开发者 https://www.devze.com 2023-01-10 11:02 出处:网络
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

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.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号