我无法从php数组中检索值

Ara*_*ind 1 php

这是代码:

我无法在第二个功能中打印网站类型.当从一个不同的函数发送"all"作为参数时,我能够打印数组.

function site_type_find($site_type)
{
 $site_type_name_array=['Youtube','Wikipedia','Mashable','Wired'];
  if($site_type="all")
  return $site_type_name_array;
  else
  return $site_type_name_array[$site_type];
}
function display_topic_category_sitetype($topic_id,$category_id,$site_type)
{
  $result=mysql_query("select topic_name from topic_table where topic_id=$topic_id");
  $result1=mysql_query("select category from categorytable where category_id=$category_id");
  $site_type_name=site_type_find($site_type);
  $resultarr=array();
  $resultarr1=array();
  $resultarr=mysql_fetch_array($result);
  $resultarr1=mysql_fetch_array($result1);
  $topic=$resultarr[0];
  $catname=$resultarr1[0];
?>
  <section>
  <header><?php echo $topic."\n";?></header>
  <article><?php echo $catname."\n";?></article>
  <article><?php echo $site_type_name."\n";?></article>
<?php
}
Run Code Online (Sandbox Code Playgroud)

Voi*_*cus 5

您应该使用==而不是=作为比较运算符.

那是在第4行:

if($site_type="all") // use two =
Run Code Online (Sandbox Code Playgroud)


Man*_*dar 5

使用==而不是=作为比较运算符.

在第4行,使用下面的代码.

if($site_type=="all") 
Run Code Online (Sandbox Code Playgroud)

哪里:

==用于checking equalityOR comparison目的.

=用于assigning valuesphp变量.