list() is behaving logical and weird at the same time

<?php
list($a, $b) = array(1, 2, 3, 4);
?>

What direction will list start processing the array? You'd expect that it'd be left to right and that's right: $a = 1, $b = 2. But where it gets confusing:

<?php
list($a, $a) = array(1, 2, 3, 4);
?>

Well, we already know list will only consider 1 and 2. So first 1 gets assigned to $a and then 2 gets assigned and that's where our story ends, right? After all, the second $a is where $b used to be, right? Wrong. The manual warns you

list() assigns the values starting with the right-most parameter.

So first $a becomes 2 and then 1. And so $a becomes 1.

This is where writing a manual becomes hard -- are you going to add a counter-warning that the slicing does behave normally? What kind of warning is that, anyways: "there is nothing to see here, move on". Do you just let this slip and hope people get that the abscence of the warning means there's nothing to be warned about? Or in the light of a strange behavior normal behavior merits a warning?

Actually, if you want to confuse someone at a tech interview, just throw list($a, $a) = array(1, 2, 3, 4); and point out how 1, 2, 3, 4 are all possible depending on where list starts processing the left and the right side -- if the left side is processed from right-to-left why not the right side too? (Because it makes no sense to do that!).

Comments

At all I do not know, that here and to tell that it is possible

I am sorry, that has interfered... At me a similar situation. Let's discuss. Write here or in PM.

At all I do not know, that here and to tell that it is possible

I am sorry, that has interfered... At me a similar situation. Let's discuss. Write here or in PM.

wow

wowo thanks

Making Sense ...

Thanks for exposing this subject. And now to add some clarity:

Only two of the values will have opcodes created for this multiple assignment operation and relate to elements 0 and 1 of the array. list construct expects array to have sequential numeric keys starting with zero, even if the keys become disordered from sorting. So, values 3 and 4 get sidelined. Because list is right associative it takes element 1 and assigns it to the right most variable $a. Next, it does the same with element 0 assigning it to the remaining $a. The leftmost $a overwrites the rightmost $a b/c the "lefty" was assigned last! The list operator is right associative since simple assignment is right associative, therefore for a multiple assignment the same holds true and keeps assignment associativity consistent.

You're just doing it wrong.

You're just doing it wrong. You're overwriting he first $a with the last $a.

Losing weight can be a very

I am really sorry i did not

I am really sorry i did not understand anything form this code .What about this Code please let me know anyone ?
My website: http://www.innovativehs.com

Its like you read my mind!

Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something. I think that you could do with some pics to drive the message home a bit, but other than that, this is great blog. A great readFootball Online Games

I am very happy to read this.

I am very happy to read this. This is the kind of manual that needs to be given and not the random misinformation t hat's at the other blogs. Appreciate your sharing this best posting. Berita Liga Spanyol

This is a fantastic website

This is a fantastic website and I can not recommend you guys enough. Full of useful resource and great layout very easy on the eyes. Please do keep up this great work... Midsummer Day

Great post you should also

Great post you should also posts about valentines day 2015 and advance
happy valentines day

Happy Valentines Day 2015

Valentine's Day.

Many thanks a lot. You really a wonderful write-up that you posted. Content that you’re undertaking like wonderful share for people like us, visitors, made the day.

Latest Love Calculator for Valentine Day to True Love Meter

thanks web web web web web

thanks
web
web
web
web
web

Valentines day status for Her wechat

good for interview

boşanma avukatı

Boşanma avukatı, İstanbul Boşanma avukatı, boşanma avukatı istanbul, boşanma, avukat arama En İyi Boşanma Avukatı

Interesting thoughts here,

Interesting thoughts here, thank you so much for exposing your ideas. Will be following your blog with a greatest interest. Thank you so much!
tanah rumah murah semarang

Hi, thank very thank! Welcome

Hi, thank very thank!
Welcome you http://projektoria.com.pl/realizacje and http://maia.poznan.pl/

obat obatan herbal

Salah satu kendala dalam memerangi kanker serviks di Indonesia adalah rendahnya kesadaran serta pengetahuan masyarakat mengenai penyakit kanker. Hal inilah yang menyebabkan sulitnya ditemukan penderita kanker yang masih berada pada tahap awal. Sehingga, 70 persen penderita kanker di Indonesia sudah berada pada stadium lanjut. Dr Ricky Susanto menyayangkan mitos yang mengatakan kanker serviks merupakan penyakit yang tidak dapat dideteksi.

“Para wanita dapat lebih memperhatikan apabila terdapat gejala seperti keputihan yang lama, pendarahan, serta timbul rasa nyeri. Karena hal-hal tersebut menunjukkan gejala awal kanker serviks. Apabila Anda mulai merasakan rasa sakit ketika buang air kecil, susah Buang Air Besar (BAB), batuk darah, dan mengalami kelumpuhan, maka menunjukkan Anda telah berada pada stadium lanjut, ” tambah dr Ricky Susanto.

Apabila sel kanker telah menyebar, tentunya pasien dapat segera mengambil salah satu dari program penyembuhan berikut: destruksi, yaitu metode pengobatan kanker serviks dengan cara dirusak secara lokal melalui pemanasan atau pendinginan; pembedahan cone biopsy, yaitu dengan memotong leher rahim; pengangkatan rahim dan sekitarnya; kemoterapi; serta radioterapi, yaitu terapi radiasi/sinar.

“Dengan semakin majunya teknologi kedokteran, selain metode pengobatan kanker serviks yang telah ada saat ini, saya optimis nantinya akan ditemukan pengobatan kanker serviks yang lebih baik lagi bagi pasien. Namun, tahap pencegahan akan selalu lebih baik daripada pengobatan. Meskipun merupakan penyakit pembunuh wanita nomor dua di Indonesia, kanker serviks merupakan jenis penyakit yang mudah untuk dideteksi. Saat ini hampir semua rumah sakit telah memiliki pelayanan untuk pendeteksian dini, melalui papsmear, kolposkopi, dan vaksinasi. Pendeteksian dengan papsmear dilakukan pada sel-sel mulut rahim di bawah mikroskop. Selain sederhana dan mudah, tingkat kepekaannya mencapai 60-95 persen,” lanjut dr. Ricky Susanto.

Sedangkan bagi wanita muda yang belum aktif secara seksual, sangat dianjurkan untuk melakukan vaksinasi kanker serviks. Vaksin HPV ini dilakukan dalam tiga tahap penyuntikan yang dilakukan dalam kurun waktu enam bulan. Berbagai pilihan untuk pencegahan kanker serviks yang ada saat ini merupakan pilihan yang pantas untuk dipertimbangkan mengingat risiko yang dapat ditimbulkan dari kanker serviks. Beberapa pilihan pengobatan seperti kemoterapi dan radiasi tidak hanya meninggalkan rasa sakit pada tubuh, tetapi juga membutuhkan waktu yang cukup lama untuk dalam proses penyembuhannya. Dengan biaya pengobatan yang tidak sedikit, tentunya perlawanan kanker serviks dengan cara pendeteksian sedini mungkin merupakan pilihan yang cukup bijaksana.

same things

Asam urat adalah suatu penyakit yang terjadi pada bagian persendian terutama sendi jari kaki, jari tangan, tumit, dengkul, siku, dan pergelangan tangan. Nyeri atau rasa sakit pada bagian persendian yang diakibatkan asam urat sangat hebat dan membuat bagian yang diserang tampak bengkak dan meradang. Namun kita juga dapat menympulkan bahwa semua rasa nyeri di persendian adalah penyakit asam urat. Untuk mengobati asam urat hanya diperlukan satu jenis obat herbal untuk mengobati asam urat, yaitu jelly gamat gold g

menurunkan berat badan

Nice sharing...

Thanks for information..

nurdiana.web.id

You actually make it seem so

You actually make it seem so easy with your presentation but I find this matter to be really something which I think I would never understand.
It seems too complex and extremely broad for me. I am looking forward for your next post, I’ll try to get the hang of it!
Obat Herbal Kanker Usus | Obat Herbal Penurun Trigliserida Tinggi | Radang Usus Besar Herbal | Obat Emfisema Herbal | Obat Sinusitis Herbal

Thanks for sharing this information brother :D

Very odd

Good luck with this!

http://www.betaalbaresokken.nl

baca panduannya untuk

baca panduannya untuk mengetahui Harga grosir jilbab murah online yang menjual jilbab instan murah yang modis serta menjadi koleksi jilbab untuk para pecinta jilbab kunjungi blog kami bisa juga anda baca selengkapnya juga jilbab syar'i cantik .

ikut share

thank you for the information,Obat Penyakit Maag Tradisional

ikut share

thank you for the information,http://greenworldobatmaag.web.id/obat-untuk-bebaskan-penyakit-maag-tradisional
we respect each other and visit each other by exchanging link..insha Allah four months
http://hargaobatacemaxs.com/pengobatan-fistula-ani-tradisional-tanpa-operasi/

bali travel online

good blog & nice info

sewa kereta di bali

cool info

sewa mobil di bali

good job

bali wisata murah

mantap gan

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