Accessing multidimensional array in Php

61 Views Asked by At

I print the multidimensional array which I get from an API and the goal is to loop over the array and check of the field [Percents] is greater than 20 but with no success: This is how the array looks like: Multidimensional array

How do I get the number which appears right after the word Percents?

2

There are 2 best solutions below

0
Imran On BEST ANSWER

You can access the Percents as below:

foreach($arrays as $array){
    if(isset($array->Percents){
        echo $array->Percents;
    }
}

Here, I am echoing the percents, you can even put it in some other variables.

0
Rakesh On

In this array, the first index is an object of Copyleaks\ResultRecord. So you would need to access it like below.

$array[0]->Percents;

If you are looping then

foreach($array as $key=>$value) {
    $value->Percents; //Percents that you are looking for
}