What I'm trying to do is take an array that I created and look for key abbreviations in that array, if it finds something it will append a variable until all item in the array have been found, then returns the appended variable.

Having trouble with it though...

function check_programs($input) {
		// Replaces the array with longer string.
		$programs = array($input);
		$check = 0;
		$return_string = '';
		while ($check <= $programs){
			if(array_search('ma', $programs) == true){
				$return_string .= "Maya, ";
				$check ++;
			}elseif(array_search('ps', $programs) == true){
				$return_string .= "Photoshop, ";
				$check ++;
			}elseif(array_search('ai', $programs) == true){
				$return_string .= "Illustrator, ";
				$check ++;
			}elseif(array_search('xn', $programs) == true){
				$return_string .= "xNormal, ";
				$check ++;
			}else(array_search('mm', $programs) == true){
				$return_string .= "MatchMover, ";
				$check ++;
			}
			return $return_string;
		}

Two points have to be noted here:

1. if you use else if conditional loop then it will go for only on condition for your input,then other matched inputs will not return strings.
2.decide your input manner, whether it is in comma separated or space separated or some thing else. Based on this explode an array called $programs using php explode function.

and also:

-> Use in_array() instead of array_search for searching string in an array.
-> remove while loop, no use here.

based on the above things i have changed your code accordingly.try with the following:

<?php
function check_programs($input)
{
		$programs = explode(" ", $input);
		$return_string = '';
		if(in_array('ma', $programs) == true){
			$return_string .= "Maya, ";
		}if(in_array('ps', $programs) == true){
				$return_string .= "Photoshop, ";
		}if(in_array('ai', $programs) == true){
				$return_string .= "Illustrator, ";
		}if(in_array('xn', $programs) == true){
				$return_string .= "xNormal, ";
		}
		if(in_array('mm', $programs) == true){
				$return_string .= "MatchMover, ";
		}
		return $return_string;
		
}
echo $string1=check_programs('ps xn');
?>

If your requirement not matches this come up with clear information.

thanks.

Yes!! Thank you very much, the changes finally made the dang thing work!

Thank you for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.