dongqu4443 2018-10-18 19:46
浏览 44

填充数组返回空白

I am retrieving data from an api using curl with php. I am able to successfully get a response from the api and retrieve the data i want from it. My problem arises whenever I try to pass the data into an array to be able to return it, as when I use var_dump() on the array it is empty. Any pointers on how to get this array to return its values would be great

// decode json string into array
$output = json_decode($output, true);

// check if the supplied data is an array
if(is_array($output)){
//loop through the first level of the array
foreach($output as $key => $value) {
   //assigning variable values

    $btcDominance = ["btc_dominance"];
   $errorMsg = $value["error_message"];
$errorCode = $value["error_code"];
$timestamp = $value["last_updated"];





//check if the next level is an array and loop through it
if(is_array($value)) {
foreach($value as $key => $values) {


//check if the next level is an array and loop through it
    if(is_array($values)) {
    foreach($values as $keys => $value3) {
    //check if the next level is an array and loop through it

        $marketCap = $value3["total_market_cap"];
        $volume = $value3["total_volume_24h"];





$values = array('btc' => $btcDominance,
'errMsg' => $errorMsg);
return $values;


}//foreach3

}//isarray 3        

}//foreach2

}//is array 2       

}//foreach1
}//is array 1



}//end of qryCmc

I think the getValues function might be the reason the array is returning as blank, but if i remove the " ='' " from this function I get an Warning: Missing argument 1 for Cmc::getValues(),

function getValues($values ='') {
return $this->output;
}
}// end of Cmc



  $cmc = new Cmc();
  var_dump($cmc->getValues());
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探