1

I have Matrix and how get value from there? The data obtained from a file, so that the matrix can be of different sizes

Thanks

2
  • 3
    A sample of your loading code would be nice. Commented Aug 2, 2010 at 23:04
  • 2
    Are you talking about a two dimensional array in PHP? If you clarify your question we won't have to guess. Commented Aug 2, 2010 at 23:05

1 Answer 1

1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.