简体   繁体   中英

wordpress Fatal error: Cannot use object of type stdClass as array in

I keep getting this error but I'm pretty sure nothing's wrong with my code: EDIT: The error also says Notice: Undefined property: stdClass::$0 in

<?php foreach ($testoppervlaktes as $oppervlakte): ?>
                    <?php 
                    foreach($testtypes as $key => $value){
                        if($oppervlakte[$value->$key == true]){                       

                        } else {               

                        }
                    }
                    ?>
                    <option data-4="" data-5="" data-6="" data-7="" value="<?php echo $oppervlakte->name ?>"<?php if(isset($_GET['oppervlakte']) && $_GET['oppervlakte'] == $oppervlakte): ?> selected<?php endif; ?>><?php echo $oppervlakte->name; ?></option>

the error is on this line

if($oppervlakte[$value->$key == true]){

everything else of my code works I keep getting this error in my html

I did a

var_dump($oppervlakte);

and from the result:

object(stdClass)#4290 (11) {
["term_id"]=>
string(2) "23"
["name"]=>
string(16) "5000m2 - 10000m2"
["slug"]=>
string(14) "5000m2-10000m2"
["term_group"]=>
string(1) "0"
["term_taxonomy_id"]=>
string(2) "23"
["taxonomy"]=>
string(11) "oppervlakte"
["description"]=>
string(0) ""
["parent"]=>
string(1) "0"
["count"]=>
string(1) "2"
["6"]=>
bool(true)
["4"]=>
bool(true)
}

I want to check if the ["6"] and ["4"] is true but there could be more or less fields that are true or false it can be ["4"] ["5"] ["6"] ["7"] all false/true or mixed

in an earlier loop I set the data to true or false

foreach($testoppervlaktes as $key => $value){
        if($value->term_id == $huidigvastgoedoppervlakteid){
            $testoppervlaktes[$key]->$huidigtypeid = true;
        }
    }

Your condition should be like that:

if($oppervlakte[$value->{$key}] == true){                       
   // your stuff
} else {               
   // your stuff    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM