Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WP Plugin – Array Re: WP Plugin – Array

#79019
Bob
Member

You can use the in_array() function for that. Here’s an example:



$post_id = 1;
$posts_for_plugin = array(1,324,34);

if ( in_array($post_id, $posts_for_plugin) ) {
echo "Yep, it's in the array";
}
else {
echo "Sorry, not in array";
}

?>

The in_array function has 2 parameters here (you can also set a third). The first parameter is the string you’re looking for in the array, which is $post_id here. The second parameter is the array in which the first parameter has to be found, here that is $posts_for_plugin. The second parameter ofcourse has to be an array.