1

我需要访问数组的键和属性。我有点困惑,我不知道如何轻松处理。

这是我运行的代码,

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)
4

1 回答 1

0

我认为你试图访问数据集$selcted

foreach ($selcted as $sel) {
    $vars = get_object_vars($sel);
    foreach ($vars as $key => $var) {
         echo $sel->$key;
    }
}
于 2013-06-20T05:57:00.137 回答