# [EMAIL PROTECTED] / 2007-01-29 16:07:39 +0200:
> [EMAIL PROTECTED] wrote:
> >What's the best way to achieve something like this:
> >explode($needle, $array)[3]
> >It's too clumsy to use temporary array, and I suppose, quite slow. Is
> >there any option, or I'll have to stick to temporary arrays?
>
> Not sure what you are trying to do.
>
> 1. Are you trying to explode the values of an array.(doesn't make sense
> I know)
>
> 2. Search for a value in a array and then return them as a new array -
> there are other php function for this.
>
> Please explain more clearly what your intentions are?
The intention is clear:
<?php
function returns_array()
{
return array_flip(array('a', 'b', 'c', 'd'));
}
$a = returns_array();
assert(2 == $a['c']);
# crash
#assert(2 == returns_array()['c']);
?>
Before anyone starts the "but this is not the PHP way" tirade, PHP
already does this with property access to objects:
<?php
function returns_arrayobject() {
return new ArrayObject(
returns_array(),
ArrayObject::ARRAY_AS_PROPS
);
}
$a = returns_arrayobject();
assert(2 == $a['c']);
assert(2 == returns_array()->c);
# still crash
#assert(2 == returns_array()['c']);
?>
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php