简体   繁体   English

php从数组中获取数据

[英]Get data from array in php

How can i get the data from my array $statistics['core.views'].我如何从我的数组 $statistics['core.views'] 中获取数据。 I have tried the doing <?php echo $statistics['core.views']['label'] ?> but it returns no data.我已经尝试过<?php echo $statistics['core.views']['label'] ?>但它没有返回任何数据。 Please any suggestion or advice please.请任何建议或意见。

// Statistics
    $statistics = array();

    // views
    $statistics['core.views'] = array(
      'label' => 'Page Views',
      'today' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('core.views', 'day'),
      'total' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('core.views'),
    );

    // signups
    $statistics['user.creations'] = array(
      'label' => 'Members',
      'today' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('user.creations', 'day'),
      'total' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('user.creations'),
    );

This only could fail, if a method returns an fatal error:如果方法返回致命错误,这只会失败:

Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('XXXX', 'day')

You can also try to dump this, to see its content您也可以尝试转储它,以查看其内容

var_dump( $statistics )

You should be sure, that there is no error.你应该确定,没有错误。 Try to enable your error output, or just take a look into the php error_log尝试启用您的错误输出,或者查看 php error_log

Try storing the other array items in variables before placing them in the main array.尝试将其他数组项存储在变量中,然后再将它们放入主数组中。 They are probably breaking the array.他们可能正在破坏阵列。 For example例如

$today = Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('core.views', 'day');

then add it to the array like this然后像这样将它添加到数组中

$statistics['core.views'] = array(
  'label' => 'Page Views',
  'today' => $today,
);
echo $statistics['core.views']['label'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM