Posts tagged with “code”

15 Feb

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.

function multi_array_key_search($needle,$haystack,$keys_found=array()){
	if(is_array($haystack)){
		foreach($haystack as $key=>$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;<br />
}

View Comments · Tags: ,

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!

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

View Comments · Tags: ,

Forcing a floated line-wrap in PHP

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

<?=($b++%4==0)?'<br class="clr" />&#8216;:NULL?&gt;

View Comments · Tags: ,
29 Apr

The Cake PHP Framework

I started using a new coding framework called Cake. It’s a style of coding based on Ruby on Rails using the “Model, View, Controller” pattern. Cake is meant to speed up the development time of web projects. I’ll try to keep this site updated on my progress. I’d ideally like to recode this website using cake once I become more familiar. Right now I’m using the code at work to create a backend website administration app.

← Previous Page 3 of 3