dqm74406 2016-05-26 06:38
浏览 193

PHP警告:usort()期望参数1为数组,在&array_slice()中给出null,期望参数1为数组,null为

function prepare_items() {
  $columns  = $this->get_columns();
  $hidden   = array();
  $sortable = $this->get_sortable_columns();
  $this->_column_headers = array( $columns, $hidden, $sortable );
  usort( $this->$data, array( &$this, 'usort_reorder' ) );
  $per_page = 5;
  $current_page = $this->get_pagenum();
  $total_items = count( $this->data );
  $this->found_data = array_slice( $this->data,( ( $current_page-1 )* $per_page ), $per_page );
  $this->set_pagination_args( array(
    'total_items' => $total_items,
    'per_page'    => $per_page
  ) );
  $this->items = $this->found_data;}

i get thia error from code above.

Warning: usort() expects parameter 1 to be array, null given in [...]

Warning: array_slice() expects parameter 1 to be array, null given in [...]

can anyone help me to solve his problems?

  • 写回答

2条回答 默认 最新

  • dpvmtdu364462 2016-05-26 06:44
    关注

    i think $this->$data returns empty. Make sure $this->$data returns array and check the value (if(!empty($this->$data)) and proceed with function

    function prepare_items() {
      $columns  = $this->get_columns();
      $hidden   = array();
      $sortable = $this->get_sortable_columns();
      $this->_column_headers = array( $columns, $hidden, $sortable );
    if(!empty($this->$data) {
      usort( $this->$data, array( &$this, 'usort_reorder' ) );
      $per_page = 5;
      $current_page = $this->get_pagenum();
      $total_items = count( $this->data );
      $this->found_data = array_slice( $this->data,( ( $current_page-1 )* $per_page ), $per_page );
      $this->set_pagination_args( array(
        'total_items' => $total_items,
        'per_page'    => $per_page
      ) );
      $this->items = $this->found_data;}}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?