Gustavo Lopes | 14 May 12:21 2012
Picon

[PHP-DEV] [RFC] [DISCUSSION] array_part()

Hi

I have a proposal to add a new function to ext/standard: array_part():

https://wiki.php.net/rfc/array_part

Comments would be very welcome, especially the constructive kind.

Please keep this on topic. In particular, avoid proposing new syntax as  
I'm not interested in that. You can of course create your own RFC for that  
purpose.

-- 
Gustavo Lopes

--

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Paul Dragoonis | 14 May 12:26 2012
Picon

Re: [PHP-DEV] [RFC] [DISCUSSION] array_part()

Can you please add some code examples on the RFC, that get outputted as
<pre> tags.

Ideally demonstrating var_dump() output to inspect the return value of your
new function to get a clear indication of the input, and resulting output.

- Paul.

On Mon, May 14, 2012 at 11:21 AM, Gustavo Lopes <glopes <at> nebm.ist.utl.pt>wrote:

> Hi
>
> I have a proposal to add a new function to ext/standard: array_part():
>
> https://wiki.php.net/rfc/**array_part<https://wiki.php.net/rfc/array_part>
>
> Comments would be very welcome, especially the constructive kind.
>
> Please keep this on topic. In particular, avoid proposing new syntax as
> I'm not interested in that. You can of course create your own RFC for that
> purpose.
>
> --
> Gustavo Lopes
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
(Continue reading)

Gustavo Lopes | 14 May 12:29 2012
Picon

Re: [PHP-DEV] [RFC] [DISCUSSION] array_part()

On Mon, 14 May 2012 12:26:11 +0200, Paul Dragoonis <dragoonis <at> gmail.com>  
wrote:

> Can you please add some code examples on the RFC, that get outputted as
> <pre> tags.
>
> Ideally demonstrating var_dump() output to inspect the return value of  
> your
> new function to get a clear indication of the input, and resulting  
> output.
>

The examples were linked from the RFC page. I've made the link more  
obvious. In any case, here is the URL:

https://gist.github.com/2660601#file_test.php

-- 
Gustavo Lopes

--

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Paul Dragoonis | 14 May 13:23 2012
Picon

Re: [PHP-DEV] [RFC] [DISCUSSION] array_part()

Hey,

Am i correct in assuming this is basically substr() for arrays.

On Mon, May 14, 2012 at 11:29 AM, Gustavo Lopes <glopes <at> nebm.ist.utl.pt>wrote:

> On Mon, 14 May 2012 12:26:11 +0200, Paul Dragoonis <dragoonis <at> gmail.com>
> wrote:
>
>  Can you please add some code examples on the RFC, that get outputted as
>> <pre> tags.
>>
>> Ideally demonstrating var_dump() output to inspect the return value of
>> your
>> new function to get a clear indication of the input, and resulting output.
>>
>>
> The examples were linked from the RFC page. I've made the link more
> obvious. In any case, here is the URL:
>
> https://gist.github.com/**2660601#file_test.php<https://gist.github.com/2660601#file_test.php>
>
>
> --
> Gustavo Lopes
>
Gustavo Lopes | 14 May 13:39 2012
Picon

Re: [PHP-DEV] [RFC] [DISCUSSION] array_part()

On Mon, 14 May 2012 13:23:27 +0200, Paul Dragoonis <dragoonis <at> gmail.com>  
wrote:

> Am i correct in assuming this is basically substr() for arrays.

No. That's a part of it. It also does indexes as keys (like array_slice)  
and multidimensional arrays, none of which have anything analogous in  
strings.

-- 
Gustavo Lopes

--

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Pierre Joye | 14 May 15:01 2012
Picon

Re: [PHP-DEV] [RFC] [DISCUSSION] array_part()

hi Gustavo,

I would add some examples inline in the RFC, with explanation, to ease
the comprehension of this new function and its possibility. The
current RFC is somehow hard to digest :)

Cheers,

On Mon, May 14, 2012 at 1:39 PM, Gustavo Lopes <glopes <at> nebm.ist.utl.pt> wrote:
> On Mon, 14 May 2012 13:23:27 +0200, Paul Dragoonis <dragoonis <at> gmail.com>
> wrote:
>
>> Am i correct in assuming this is basically substr() for arrays.
>
>
> No. That's a part of it. It also does indexes as keys (like array_slice) and
> multidimensional arrays, none of which have anything analogous in strings.
>
>
> --
> Gustavo Lopes
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--

-- 
Pierre

(Continue reading)

Paul Dragoonis | 14 May 15:41 2012
Picon

Re: [PHP-DEV] [RFC] [DISCUSSION] array_part()

On Mon, May 14, 2012 at 2:01 PM, Pierre Joye <pierre.php <at> gmail.com> wrote:

> hi Gustavo,
>
> I would add some examples inline in the RFC, with explanation, to ease
> the comprehension of this new function and its possibility. The
> current RFC is somehow hard to digest :)
>

Yes, that's what I was meaning earlier but was on my mobile phone. Thanks
Pierre.

Gustavo, why would I use array_part() if I could use array_slice() to get
the parts of an array between two offsets.

>
>
> Cheers,
>
> On Mon, May 14, 2012 at 1:39 PM, Gustavo Lopes <glopes <at> nebm.ist.utl.pt>
> wrote:
> > On Mon, 14 May 2012 13:23:27 +0200, Paul Dragoonis <dragoonis <at> gmail.com>
> > wrote:
> >
> >> Am i correct in assuming this is basically substr() for arrays.
> >
> >
> > No. That's a part of it. It also does indexes as keys (like array_slice)
> and
> > multidimensional arrays, none of which have anything analogous in
(Continue reading)

Gustavo Lopes | 14 May 16:03 2012
Picon

Re: [PHP-DEV] [RFC] [DISCUSSION] array_part()

On Mon, 14 May 2012 15:41:25 +0200, Paul Dragoonis <dragoonis <at> gmail.com>  
wrote:

> Gustavo, why would I use array_part() if I could use array_slice() to get
> the parts of an array between two offsets.
>

Obviously, if you want to do something that array_slice() already does,  
then you wouldn't have a lot of pressing reasons to use this instead. But  
this is not a very interesting question.

On the other hand, if you're asking what are differences between this and  
array_slice(), then:

* array_slice() only does slicing at the level 1 (it has no  
multidimensional slicing that would allow doing something like  
array_column(), see https://github.com/php/php-src/pull/56 )
* array_slice() only operates in an 'index-as-offset' mode, which is less  
efficient than 'index-as-key'. array_part() allows you to choose:

$arr = [-1 => 'a', 0 => 'b'];
array_slice($arr, 0, 1) // 'a'
array_slice($arr, -1, 1) // 'b'
array_part($arr, [0]) // 'a'
array_part($arr, [-1]) // 'b'
array_part($arr, [-1], true) // 'a'

* array_slice() has side-effects; it resets the internal array pointer.
* array_slice() can preserve keys, array_part() cannot because when  
collapsing levels this would mean the possibility of overwriting elements.
(Continue reading)


Gmane