Posts Tagged ‘loop’
1 หน้า1
jQuery .each เขาใช้กันยังไง

เพื่อนผมท่านหนึ่งสร้างฟอร์มให้ยูสเซอร์ป้อนค่า ครั้งละหลายๆค่า จะได้ไม่เสียเวลา โดยเพื่อนท่านนั้นใช้เท็กบ็อกแบบอะเรย์
<form id="form1" name="form1" method="post" action=""> <p> Product : <input type="text" name="product[]" id="product[]" /> </p> <p> Product : <input type="text" name="product[]" id="product[]" /> </p> <p> <input type="submit" name="button" id="button" value="Submit" /> </p> </form>
คำถามในพันธิพ
อันนี้เป็นคำถามที่พันธิพ ไม่รู้ว่าจะเอาไปทำอะไรเหมือนกัน ผมได้เขียนตอบไป เลยเอามาให้ท่านๆดูกัน เผื่อเก็บเอาสิ่งละเล็กสิ่งละน้อย ในคำถามคำตอบ ไปประยุกต์การเขียนโปรแกรมของตนเอง
คำถาม :
คือ ผมต้องการให้ array เก็บ
$arr_column = array(“A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”,”I”,”J”,”K”,”L”,”M”,”N”,”O”,”P”,”Q”,”R”,
“S”,”T”,”U”,”V”,”W”,”X”,”Y”,”Z”,”AA”,”AB”,”AC”,”AD”,”AF”,”AG”,”AH”,”AI”,”AJ”,”AK”,”AL”,
“AM”,”AN”,”AO”,”AP”,”AQ”,”AR”,”AS”,”AT”,”AU”,”AV”,”AW”,”AX”,”AY”,”AZ”,”BA”,”BB”,”BC ฯลฯ
ต่อ ไปเรื่อยๆ จนถึง ZZ หน่ะครับ แต่ทีนี้มานั่งเขียนเอาคงตายแน่ ผมเลย ลองใช้ for loop มาช่วยแอดแต่ทำไม่สำเร็จอ่ะครับ ยัง งงๆ กะ loop อยู่ พี่ๆ ช่วยดูให้หน่อยคับ
คำตอบ 1 :
$arr = array(); for ($i = 0; $i < 26; $i++) $arr[] = chr(65+$i); for ($i = 0; $i < 26; $i++) for ($j = 0; $j < 26; $j++) $arr[] = chr(65+$i) . chr(65+$j);
คำตอบของพ้ม :
$arr_results = array(); $A_Z = range( 'A','Z' ); foreach( $A_Z as $key1=>$value1 ){ foreach( $A_Z as $key2=>$value2 ){ $arr_results[] = $value1.$value2; } } $arr_results = array_merge( $A_Z , $arr_results );
ผมเองถ้าเจอความต้องการประเภทเรียงลำดับ 1-10 a-z อะไรเทือกๆนี้ ผมเลือกจะใช้ range() มันเร็วดีครับ ลองต่อยอดฟังก์ชั่นตัวนี้ดูนะครับ ว่ามันใช้งานยังไง ประยุกต์ได้เยอะทีเดียว
1 หน้า1
Categories
-
Recent Posts
- เครื่องฟ้อง error จอฟ้า STOP: c0000221 {Bad Image Checksum}
- The application failed to initialize properly(000000)
- อยากเปิดร้านคอม ทำยังไงดี?
- Wordpress Theme PhotoMadness ธีมสำหรับคนชอบถ่ายภาพ
- mail server : ติดตั้ง argosoft mail server
- mail server สร้างเมล์เซิฟเวอร์ทดสอบโค้ดส่งอีเมล์ ด้วย hmailserver
- php redirect สั่งเด้งฟ้าผ่า
- javascript ห้ามคลิกขวา
- CSS IE Bugs แมลงร้ายในไออี 6
- PHP round ปัดเศษ
- PHP ceil() ปัดเศษขึ้น
- Gravatar สร้างร่างใหม่สู่โลกออนไลน์
- PHP floor() ปัดเศษลง
- แจกโค้ด php คำนวณอายุ
- PHP date() ฟังก์ชั่นจัดการวัน-เวลา
Tags
Array Back to the basic calendar CAPTCHA chart CSS Dreamveawer error firefox firefox plugin FPDF General gmail google hotmail html icon icons javascript jQuery jquery plugin jquery slide jquery tooltip jQuery tutorial jQuery UI loop Mac MySQL Other PHP plugin program programming slide slide show SMF smf themes smf themes download smf themes free smf themes thai SQL sql function tooltip Wordpress wordpress plugin
