Ryan Rampersad
Opinions, Thoughts and Ideas - PHP, Java and Javascript
  • Home
  • About
  • Contact
Browse: Home / array

array

ArrayList of Objects to Array of Objects

By Ryan on November 30, 2009

Sometimes you need to use an ArrayList. It can be when you’re lazy or when you want flexibility. Eventually, you’ll want to get away from the ArrayList and use your stores objects as standard object array. Doing this isn’t very complicated but it is slightly hidden.
We’re going to pretend for a moment that we have [...]

Posted in Java | Tagged array, arraylist, Java, objects | Leave a response

Final ArrayLists can Change

By Ryan on September 22, 2009

This wasn’t a revelation or anything. My AP Computer Science class was wondering what would happen if one were to set an ArrayList to final. Remember, when you add the final prefix to an variable declaration, it becomes constant and therefore not changeable. (That definition is where we got lost.)
I wrote some sample code that [...]

Posted in Java | Tagged array, change, final, Java, list | 2 Responses

json cookies with PHP

By Ryan on July 26, 2009

I needed to use a cookie to store a hash string so a user would be remembered the next time they come to visit a site. I was required to store their user id (numeric) and also a secret string that gets hashed. This typically would have required two cookies but I didn’t want two [...]

Posted in PHP | Tagged array, cookie, json, PHP | Leave a response

Randomize an Array with Mootools

By Ryan on July 15, 2009

Mootools doesn’t offer a native way to randomize an array but it does offer a way to get a single random element from an array.
You can extend Mootools to have an Array.randomize method. It’s really easy to do.

Array.implement({
randomize: function() {
return this.sort(function() {return 0.5 – Math.random();});
}
});

Now you can easily call randomize on an array and you’ll [...]

Posted in Mootools | Tagged array, Mootools, randomize | Leave a response

Random Element from Array in PHP

By Ryan on February 11, 2009

There is a function called array_rand but it only returns the key for a random element in an array. So here’s a quick function for you that can do it all in just a couple of lines.

function array_random($array) {
return $array[array_rand($array)];
}

Yes, the word array does appear four times, but that isn’t to confuse you but make [...]

Posted in PHP | Tagged array, element, PHP, random | 2 Responses

Recent Posts

  • Create a Branch and Switch to it in Git
  • Setting Build Path has Encountered a Problem in Eclipse
  • Queue Ajax Requests in Mootools
  • CakePHP 1.3 Helper $text truncate error
  • CakePHP – 1and1 – 500 Internal Server Error

Tags

(fluff)Grabber 2.7 2009 Apple array beta blog blogs Browser Browsers CakePHP chrome CSS Design Error Firefox fluff friends fluff grabber free Google html iGoogle internet explorer Java Javascript mac Microsoft Mootools music PHP plugin plurk program review School SEO solution string tip Tips update vista Windows windows 7 Wordpress

Search

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
QC: