i have this code that will check the array contains the specific string and outputs the data needed, but it is inside a function thus the output was done using a concatenate “.=”, i did try the in_array function in its basic form
i.e
$show = array();
$show[] = "dog";
$show[] = "doga";
$show[] = "dogasd";
$show[] = "cat asd";
print_r($show);
if(in_array("cat asd", $show))
{
echo "found";
}
else
{
echo "not found";
}
and it is working, but in here:
public function personal(){
$sql_field = "SELECT * FROM somewhere WHERE show_field = 1";
$result = mysql_query($sql_field);
$num = mysql_num_rows($result);
$show = array();
for($i=0;$i<$num;$i++)
{
$row = mysql_fetch_assoc($result);
$show[] = $row['field_name']."<br>";
}
$block .= "<tr>";
$block .= $show[0];
if(in_array("firstName", $show))
{
$block .= "<td style=\"width: 250px;\"><div class=\"fields\"><input type=\"text\" title=\"First Name*\" value=\"{$this->detail("firstName")}\" name=\"first_name\" class=\"placeholder textbox-long\" /></div></td>";
}
if(in_array("lastName", $show))
{
$block .= "<td style=\"width: 250px;\"><div class=\"fields\"><input type=\"text\" title=\"Last Name*\" value=\"{$this->detail("lastName")}\" name=\"last_name\" class=\"placeholder textbox-long\" /></div></td>";
}
$block .= "</tr>";
}
it always outputs false thus not displaying anything, i tried this with a non array variable and its working fine, so my guess is that array does not work great inside a function? correct me if i’m wrong here. And i need the array for this functionality to work
any ideas guys?
Thank You 🙂
in_array()works just fine inside of functions, however you’re expecting it to search for a substring, which it does not do. If you were to search forfirstName<br>it would find what you’re looking for since you addedfirstName<br>to the array, butfirstNameis not in the array.