array_slice confused about negative length

Why is the second array below empty? It seems array_splice cannot grok negative length, despite its docs.

<?php
$array
= array('a' => '1');

// GOOD
print_r(array_slice($array, 010));

// WTF. Why empty array?
print_r(array_slice($array, 0,  -10));
?>

Array
(
    [a] => 1
)
Array
(
)

Comments

It does work, but differently

As commenting was inoperative due to a site issue, I wrote my comment as a blog post.

In short, it does work as designed and specified, but it may not perhaps be what you would intuitively expect (i.e. counting back 10 elements starting at the start point). Instead, it counts forward from the start point, until 10 elements before the end point (which in this case lies well before the start point, even outside the array), which explains why the empty array is returned.

Is almost every post on the

Is almost every post on the site from people who can't read the docs correctly. Come on.

The author was expecting to work as the negative offset does, not the negative count:

array_slice($array, -1, 10);

Really your post is really

Really your post is really very good and I appreciate it. It’s hard to sort the good from the bad sometimes, but I think you’ve nailed it. You write very well which is amazing. I really impressed by your post.
roses south africa

Really great post.Thanks for

Really great post.Thanks for providing this code.It's really help me.
mumbai seo

Hi there great website! Does

Hi there great website! Does running a blog such as this take a large amount of work? I've very little expertise in computer programming but I had been hoping to start my own blog in the near future. Anyways, should you have any recommendations or techniques for new blog owners please share.
skin moles removal

Thanks for the nice news. It

Thanks for the nice news. It was a real cool read for more. Keep up.
divorce forms

This looks absolutely

This looks absolutely perfect. All these tinny details are made with lot of background knowledge. I like it a lot. This was a useful post and I think it is rather easy to see from the other comments as well that this post is well written and useful.
varicose veins cure

handscraped flooring

Nice content, I trust it is a nice handscraped flooring. Need to see fresh content next time.

I tried your suggestion and

I tried your suggestion and it didn't work. Instead what had happened is the rest of my template stopped working. Thanks for sharing. Good post. But put more data. handmade amish furniture

Wie Werbung für die PKV

Wie Werbung für die PKV ankommt.

Die Visa Card bestellen. Ein

Die Visa Card bestellen.
Ein Smartphone kaufen.
Ein Smartphone im Test.
Ein Smartphone kaufen.
Ein Smartphone kaufen.

Einen Private

Einen Private Krankenversicherung Vergleich online testen.
Den PKV-Test machen.
Die Mastercard beantragen
Eine Kreditkarte testen.

Versicherungsvergleich Verkeh

I have been reading blogs on

I have been reading blogs on this subject for a few hours now and your content is the most informed I have read thus far. Thanks for putting this information in one place.
cna training

interesting post, thanks for

interesting post, thanks for the useful article.

Totally, the actual write-up

Totally, the actual write-up is really the very best in that will worthwhile matter. I really fit in jointly with your results and certainly am going to keenly seem to be toward your own upcoming improvements. Just telling many thanks could not only be sufficient, for your exceptional readability as part of your composing.I'll use this information to provide college papers for my friends.

Really your post is really

Really your post is really very good and I appreciate it. It’s hard to sort the good from the bad sometimes, but I think you’ve nailed it. You write very well which is amazing. I really impressed by your post.

divorce lawyers

It is great to have the

It is great to have the opportunity to read a good quality article with useful information on topics that plenty are interested on
PW0-100 exam
70-299 exam
TK0-201 exam
LX0-102 exam
PK0-003 exam
DC0-200 exam
642-982 exam
642-457 exam

The above information is

The above information is appropiate and just what I was looking for. A must read for the layman wanting a brief and precise information. We can do with a little addition of the facts in future.
divorce papers

It is so lucky to read your

It is so lucky to read your blog,it is full of useful message.I wish we both can do better in the future.It great honor if you can visit our website,and give us some suggestion.
642-971 dumps
412-79 dumps
JN0-100 dumps
JK0-018 dumps
642-427 dumps
640-821 dumps
70-562 dumps
70-624 dumps

He added that songs “are

He added that songs “are entirely within the operatic tradition” and that he used “sustained symphonic music to unify entire scenes. bijuterii He prepared himself for that task, he wrote, “by further study in counterpoint and modern harmony.”

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options