Vastermonster is Paul Thrasher's personal blog. This is my space to write and post whatever I'm into at the moment. I will mostly post about php code, design, strange videos, internet chaos, simplicity and cleverness -- fairly in-often.

Posts tagged with “code”


Find all the values of a key in an array

This is a recursive PHP function that searches all of the keys in an array and pulls out their values.

<pre id="geshi_code">function multi_array_key_search($needle,$haystack,$keys_found=array()){
	if(is_array($haystack)){
		foreach($haystack as $key=&gt;$val){
			if(is_array($val)){
				$keys_found = multi_array_key_search($needle,$val,$keys_found);
			}else{
				if($key==$needle){
					$keys_found[] = $val;
				}
			}
		}
		return $keys_found;
	}
	return false;
}

February 15th, 2008 / Tags: code, php / Trackback

Alternating background colors

I just wrote some pretty quick code for the age-old problem of alternating colors in a table. I don’t know how this could get any simpler. Sweet!

<pre id="geshi_code">&lt;? foreach($posts as $post){?&gt;
	&lt;div class=&quot;&lt;?=($c++%2==1)?'odd':NULL?&gt;&quot;&gt;
		&lt;?=$post?&gt;
	&lt;/div&gt;
&lt;? }?&gt;
&lt;style&gt;
	.odd{background-color:red;}
&lt;/style&gt;

February 15th, 2008 / Tags: code, php / Trackback

Forcing a floated line-wrap in PHP

For every 4 floated elements, wrap to the next line:

<?=($b++%4==0)?’<br class="clr" />’:NULL?>

February 15th, 2008 / Tags: code, php / Trackback


← Previous