Jump to content

[SOLVED] How do I compare a variable to a function array?


pneudralics

Recommended Posts

Want to compare name from form to badword list, but can't seem to get it to compare.

function badword() {
  array("badword1","badword2","badword3")
}
$badword = badword();
//$name comes from form
$name = $_POST['name'];
if ("$name" != "$badword") {
//if not badword do this
}
else {
//bad word
}

function badword() {
  array("badword1","badword2","badword3")
}

Should be the following for it to work:

function badword() {
  return array("badword1","badword2","badword3");
}

 

As a whole:

<?php
function badword() {
  return array("badword1","badword2","badword3");
}
$badwords = badword();
if (!in_array($_POST['name'],$badwords)) {
//
//  not a bad word
//
} else {
//
// bad word
//
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.