douzen3516 2014-09-01 05:16
浏览 70
已采纳

如何显示具有特定值/字符的数组元素?

I Have A json Array from hxxp://best1st.info/Moviedb/json.php?m=tt2015381&o=json

Here is sample of the array output :

. and so on
.
. 
[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
    (
.
.
. and so on

I want to check if in "ALSO_KNOWN_AS" Element, have "Argentina" word , If "ALSO_KNOWN_AS" Element have the "Argentina" word, then display it (the value).

I have try to do it (search with google and here on stackoverflow), but seem my code dont work, Can some one here help me to fix it , here is my code

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

$alsoKnownAs = $newdata->ALSO_KNOWN_AS;

if (in_array('Argentina', $alsoKnownAs)) {
    echo "Match found";
    // echo the-array-value
}

else
{
echo "Match not found";
return false;
} 

Thanks You

  • 写回答

3条回答 默认 最新

  • dongwuge6201 2014-09-01 05:29
    关注

    try this

    $url   = 'http://best1st.info/Moviedb/json.php?m=tt2015381&o=json';
    $newdata = json_decode(file_get_contents($url));
    $found = false;
    
    foreach($newdata->ALSO_KNOWN_AS as $value)
    {
        if(strpos($value, "Argentina") !==false)
        {
            echo $value;
            echo "<br/>";
            $found = true;
        }   
    }   
    
    if($found===false)
    {
        echo "Not found";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功