php

How to check if a value exists in an array in PHP

In this tutorial, we are going to see how to check if a value exists in an array in PHP. You can use PHP’s in_array() function to check whether or not a value exists in an array.
 

How to check if a value exists in an array in PHP
<?php
	$langages = array("PHP", "Java", "Python", "HTML");
	if(in_array("Python", $langages)){
		echo "Python has been found in languages.";
	}

	if(in_array("JavaScript", $langages)){
		echo "JavaScript has been found in languages.";
	}
?>

Output:

Python has been found in languages.

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *