php array


how can i search the string of a key in a array?

for example if i had $test = array(':colour'=>'red', ':name'=>'john', 'age'=>13);

how could i search the key of each value and check if it begins with a colon?

Who is Participating?
Greg AlexanderLead DeveloperCommented:
Here is a simple example of looping through it:

$test = array(':colour'=>'red', ':name'=>'john', 'age'=>13);

foreach($test as $k => $v){
	// now you have looped through each item, build in your search in your case a :
	if($k[0] == ':'){
		//here you would put all the matches into another array or echo them out
		echo "I have a colon ($k => $v)<br>";
		$colon_array[$k] = $v;

// now show the colon items
echo "<pre>";
echo "</pre>";

Open in new window

MK15Author Commented:
thank you, your help is appreciated:)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.