donglei7152 2014-08-31 15:36
浏览 27
已采纳

如何基于远程资源的类的一部分创建新数组

I very new in php programing, and I have try to search on google and this stackoverflow for this solution but still not get it

I'm using the following code;

$url   = 'http://best1st.info/Moviedb/json.php?m=tt2015381&o=json';
$newdata = json_decode(file_get_contents($alsoKnownAs));

$alsoKnownAs = $data['ALSO_KNOWN_AS'];
echo "<pre>";
$newdata = json_decode(file_get_contents($alsoKnownAs));
echo "<pre>";
print_r($newdata);

I try to manipulate Array from IMDB data, if the array output like :

. and so on
.
.
[TOP_250] => 52
[OSCARS] => 
[AWARDS] => 
[NOMINATIONS] => 
[VOTES] => 166,773
[LANGUAGE] => Array
    (
        [0] => English
    )

[COUNTRY] => Array
    (
        [0] => USA
        [1] => UK
    )

[STORYLINE] => On planet Earth in 1988, young Peter Quill ( ) sits in the waiting room of a hospital...
[ALSO_KNOWN_AS] => Array
    (
        [0] => Guardianes de la galaxia = Argentina
        [1] => Qalaktikanin Mühafizeçileri = Azerbaijan
        [2] => Пазителите на Галактиката = Bulgaria (Bulgarian title)
        [3] => Guardiões da Galáxia = Brazil
    )

[RELEASE_DATES] => Array
    (
        [0] => USA = 21 July 2014
        [1] => UK = 24 July 2014
        [2] => Canada = 29 July 2014
        [3] => Argentina = 31 July 2014
.
.
. and so on

How I create a New Array that just have "ALSO_KNOWN_AS" values?

Thanks you

  • 写回答

1条回答 默认 最新

  • doudun3910 2014-08-31 15:47
    关注

    Simple. As the data you require is already saved as an array you can retrieve it with;

    $alsoKnownAs = $newdata->ALSO_KNOWN_AS;
    

    So your code would look like this;

    $url   = 'http://best1st.info/Moviedb/json.php?m=tt2015381&o=json';
    $newdata = json_decode(file_get_contents($url));
    
    $alsoKnownAs = $newdata->ALSO_KNOWN_AS;
    

    You can then loop over the values with the following;

    foreach($alsoKnownAs as $value) {
        echo '<pre>' . $value . '</pre><br>'; // to print each row of the data
        // $value is the value of each part of the array in turn, starting from 0
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog