Array Helper |
[eluser]TheFuzzy0ne[/eluser]
Hi everyone. Here's my array helper, I thought I should post it in case anyone else finds it useful. It just needs to be copied into a file named "array_helper.php", and placed in "application/helpers". It will play nice with the Array helper that already exists. I was looking for a way to get the first key from an associative array, and figured I should cater for other common array activities. The content has been heavily inspired from the guys who commented on this page: http://www.php.net/array_keys One advantage of the helper file is that it can help keep your code understandable, maintainable, and self-documenting. Comments and feedback welcome. Code: <?php
[eluser]xwero[/eluser]
I would remove the array_first_value and the array_last_value functions as they only make your application slower.
[eluser]TheFuzzy0ne[/eluser]
Any idea why we can't pass parameters in by reference? I'm not sure if this is a bug or not, I can't imagine why it shouldn't work as expected.
[eluser]xwero[/eluser]
You can, the problem was that i used this test code Code: $test = 'array_shift'; Code: array_shift(array(1,2)); Quote:Fatal error: Only variables can be passed by referenceI will correct it on my blog later, thank you for pointing out my stupidity
[eluser]TheFuzzy0ne[/eluser]
Whoops. I thought it was strange that it wouldn't work, so I tested it with a string, but I made exactly the same mistake... Only I got this message: Quote:Fatal error: Cannot pass parameter 1 by reference So it wasn't quite so obvious to me either. Well done for spotting it! |
Welcome Guest, Not a member yet? Register Sign In |