Showing posts with label arrays. Show all posts
Showing posts with label arrays. Show all posts

Monday, June 11, 2012

PHP sort multidimensional array by value


How can I sort this array by the value of the "order" key? Even though the values are currently sequential, they will not always be.

Friday, June 8, 2012

List of Big-O for PHP functions


After using PHP for a while now, I've noticed that not all PHP built in functions as fast as expected. Consider the below two possible implementations of a function that finds if a number is prime using a cached array of primes.

Tuesday, June 5, 2012

PHP PDO: Can I bind an array to an IN() condition?


I'm curious to know if it's possible to bind an array of values to a placeholder using PDO. The use case here is attempting to pass an array of values for use with an IN() condition. I'm not very good at explaining, so here's some psuedocode to demonstrate... I'd like to be able to do something like this:

Friday, June 1, 2012

Strange behaviour after loop by reference - Is this a PHP bug?


I just had some very strange behavior with a simple php script I was writing. I reduced it to the minimum necessary to recreate the bug:

In Java, how can I test if an Array contains a certain value?


I have a String[] with values like so:




public static final String[] VALUES = new String[] {"AB","BC","CD","AE"};

Thursday, May 31, 2012

PHP Arrays: A good way to check if an array is associative or sequential?


PHP treats all arrays as associative, so there aren't any built in functions. Can anyone recommend a fairly efficient way to check if an array contains only numeric keys?

Wednesday, May 30, 2012

How to delete an element from an array in php?


does anyone know an easy way to delete an element from a php array? I mean so that foreach($array) no longer includes that element. I thought that setting it to null would do it, but apparently not.

Tuesday, May 29, 2012

What is the best way to add options to a select from an array with jQuery?


What is the best method for adding options to a select from a JSON object using jQuery?

How to concatenate two arrays in Java?


I need to concatenate two String arrays in Java.




void f(String[] first, String[] second) {
String[] both = ???
}

array.contains(obj) in JavaScript


What is the most concise and efficient way to find out if a JavaScript array contains an obj?

Monday, May 21, 2012

JavaScript: Check if object is array?


I'm trying to write a function that either accepts a list of strings, or a single string. If it's a string, then I want to convert it to an array with just the one item. Then I can loop over it without fear of an error.

Friday, May 18, 2012

PHP"s count(), O(1) or O(n) for arrays?


do you know if count() in PHP really counts the all elements of a PHP-array, or if this value is cached somewhere and just needs to be retrieved?

Wednesday, May 16, 2012

How do I pick only the first few items in an array?


Here's something simple for someone to answer for me. I've tried searching but I don't know what I'm looking for really.

Creation of Arrays in Java (The C++ Style)


Why can't we make arrays in Java like this:




int marks[5];

Tuesday, May 15, 2012