Although PHP boasts a huge number of array related functions, unfortunately there is no native function to extract keys from a multidimensional array because array_keys only supports one-dimensional arrays.
For those occasions when you need it, array_keys_multi might help you.
Zend_Db has a nice function called quoteInto(). As it is described in the documentation - "The method simply interpolates the value into the string, escapes special characters, and applies quotes around it.".
Let's say you have an sql query which looks like this:
- SELECT * FROM users WHERE enabled = ? AND country = ?
You wouldn't be able to use the native quoteInto function to replace both question marks in the sql without processing the same string twice:
- $users = new Users();
- $sql = 'SELECT * FROM users WHERE enabled = ? AND country = ?';
- $sql = $users->getAdapter()->quoteInto($sql, 1);
- $sql = $users->getAdapter()->quoteInto($sql, 'UK');
This would get you
- SELECT * FROM users WHERE enabled = 1 AND country = 'UK'
Unfortunately this is not the best way to do it. Imagine what the code would look like if you needed to replace 3, 5 or even more placeholders.
This is where our custom extension to Zend_Db_Table_Abstract comes in handy.
Unfortunately the native PHP's DOMDocument class does not allow you to create an xml document from a multidimensional array or save it to one.
Here is a class, which adds these capabilities - by using DOMDocumentExt you can now call loadArray or saveArray functions to do the loading and saving tasks respectively.
As an added bonus you can also use function called getPathValue, which accepts one parameter - $path - a string in
root/child1/child2/../childN format. It will convert the current document tree to an array and will return the contents of the specified path if such exists (or null if such path does not exist).
There are times when you need to get a string of random characters of the specified length. It could be the default password for a new account or a unique identifier for something (you would probably be better off generating a guid) in your database.
Here is a function for those occasions. It generates a string of the specified length consisting of random characters. You can choose which type of characters to include - lowercase, uppercase, numeric or special.