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.
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 />
}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?>“>
<?=$post?>
</div><br />
<? }?><br />
<style>
.odd{background-color:red;}<br />
</style>Forcing a floated line-wrap in PHP
For every 4 floated elements, wrap to the next line:
<?=($b++%4==0)?'<br class="clr" />‘:NULL?>
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.