如何在数组中打印属性和键值


How to print properties and key value in array

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

这是我运行的代码,

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)

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

foreach ($selcted as $sel) {
    $vars = get_object_vars($sel);
    foreach ($vars as $key => $var) {
         echo $sel->$key;
    }
}