我的变量$ X成立:阵列错误 - 无效的参数 - PHP
object(stdClass)#3 (5) {
["polarity"]=> string(7) "neutral"
["subjectivity"]=> string(9) "objective" ["text"]=> string(0) ""
["polarity_confidence"]=> float(0.77262067409886)
["subjectivity_confidence"]=> float(0.54271560213894)
}
以上是$ x的从的var_dump的输出。
我想获得极性值(“中性”)。
我尝试以下,但得到警告:()提供的foreach无效参数
foreach($x->polarity as $polarity) {
$value = $x->polarity[0];
var_dump ($value);
}
只需使用'$ x->极性',无需用于循环 –
是的,不需要循环直接使用'echo $ x->极性' –