Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在PHP中从数组中获取数据_Php_Arrays_Multidimensional Array - Fatal编程技术网

无法在PHP中从数组中获取数据

无法在PHP中从数组中获取数据,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,我的数组是这样的。我想把[perm_name]数组和[type_name]数组与[selectdata]数组分开。我无法解决这个问题。请帮帮我 array(1) { ["selectData"]=> array(2) { ["perm_name"]=> object(CI_DB_mysql_result)#17 (8) { ["conn_id"]=> resource(28) of type (mysql link per

我的数组是这样的。我想把[perm_name]数组和[type_name]数组与[selectdata]数组分开。我无法解决这个问题。请帮帮我

    array(1) {
  ["selectData"]=>
  array(2) {
    ["perm_name"]=>
    object(CI_DB_mysql_result)#17 (8) {
      ["conn_id"]=>
      resource(28) of type (mysql link persistent)
      ["result_id"]=>
      resource(34) of type (mysql result)
      ["result_array"]=>
      array(2) {
        [0]=>
        array(7) {
          ["permission_id"]=>
          string(1) "1"
          ["permission_name"]=>
          string(4) "news"
          ["default_is_edit"]=>
          string(1) "Y"
          ["default_is_view"]=>
          string(1) "Y"
          ["default_is_delete"]=>
          string(1) "Y"
          ["default_is_personal"]=>
          string(1) "Y"
          ["active"]=>
          string(1) "Y"
        }
        [1]=>
        array(7) {
          ["permission_id"]=>
          string(1) "8"
          ["permission_name"]=>
          string(13) "movies & play"
          ["default_is_edit"]=>
          string(1) "Y"
          ["default_is_view"]=>
          string(1) "Y"
          ["default_is_delete"]=>
          string(1) "Y"
          ["default_is_personal"]=>
          string(1) "Y"
          ["active"]=>
          string(1) "Y"
        }
      }
      ["result_object"]=>
      array(0) {
      }
      ["custom_result_object"]=>
      array(0) {
      }
      ["current_row"]=>
      int(0)
      ["num_rows"]=>
      int(2)
      ["row_data"]=>
      NULL
    }
    ["type_name"]=>
    object(CI_DB_mysql_result)#18 (8) {
      ["conn_id"]=>
      resource(28) of type (mysql link persistent)
      ["result_id"]=>
      resource(37) of type (mysql result)
      ["result_array"]=>
      array(5) {
        [0]=>
        array(4) {
          ["user_type_id"]=>
          string(1) "1"
          ["user_type"]=>
          string(5) "Admin"
          ["is_active"]=>
          string(1) "Y"
          ["last_modifiled"]=>
          string(19) "2012-10-05 10:38:41"
        }
        [1]=>
        array(4) {
          ["user_type_id"]=>
          string(1) "3"
          ["user_type"]=>
          string(9) "Developer"
          ["is_active"]=>
          string(1) "Y"
          ["last_modifiled"]=>
          string(19) "2012-10-05 10:32:11"
        }


      }
      ["result_object"]=>
      array(0) {
      }
      ["custom_result_object"]=>
      array(0) {
      }
      ["current_row"]=>
      int(0)
      ["num_rows"]=>
      int(5)
      ["row_data"]=>
      NULL
    }
  }
}
帮我摆脱困境。 提前感谢。

请尝试以下操作:

$permName = $array['selectData']['perm_name'];
$typeName = $array['selectData']['type_name'];
试试这个

function array_separator($val, $key, $identifier) {
  if ($key == $identifier) { // perm_name
    // do foreach for the perm_name subarray
  } else { // type_name
    // do foreach for the type_name subarray
  }
}

$select_data_array = array(/* the selectData subarray i.e. $array['selectData'] */);

array_walk($select_data_array, 'array_separator', 'perm_name');

希望我答对了您的问题。

是的,这很有效,但无法使用foreach循环遍历数组…获取错误无法使用CI\u DB\u mysql\u类型的对象作为数组