我需要访问数组的键和属性。我有点困惑,我不知道如何轻松处理这个问题。
这是我运行的代码,
foreach ($posts as $key=> $value){
if($value->total_skill!='na'&& $value->total_skill!='0'){
$selcted = $wpdb->get_results("SELECT `$selection` FROM wp_skilllist WHERE First_name = '$value->First_Name' ");
var_dump($selcted);
}
我得到以下结果。我注意到数组中有很多数组。我需要访问 擅长并打印他们的结果。
作为一个例子
FMS_Web_tec_HTML 4
FMS_Web_tec_CSS 3
FMS_Web_tec_XML 4
FMS_Web_tec_JavaScript 2
array (size=1)
0 =>
object(stdClass)[257]
public 'FMS_Web_tec_HTML' => string '4' (length=1)
public 'FMS_Web_tec_CSS' => string '3' (length=1)
public 'FMS_Web_tec_XML' => string '4' (length=1)
public 'FMS_Web_tec_JavaScript' => string '2' (length=1)
array (size=1)
0 =>
object(stdClass)[258]
public 'FMS_Web_tec_HTML' => string '3' (length=1)
public 'FMS_Web_tec_CSS' => string '3' (length=1)
public 'FMS_Web_tec_XML' => string '2' (length=1)
public 'FMS_Web_tec_JavaScript' => string '2' (length=1)
array (size=1)
0 =>
object(stdClass)[257]
public 'FMS_Web_tec_HTML' => string '3' (length=1)
public 'FMS_Web_tec_CSS' => string '2' (length=1)
public 'FMS_Web_tec_XML' => string '3' (length=1)
public 'FMS_Web_tec_JavaScript' => string '2' (length=1)
答案 0 :(得分:0)
我认为您尝试访问$selcted
foreach ($selcted as $sel) {
$vars = get_object_vars($sel);
foreach ($vars as $key => $var) {
echo $sel->$key;
}
}