|
|
|
การเขียน foreach + if else ตรวจสอบหลายเงื่อนไขในอาร์เรย์ ต้องเขียนยังไงคะ |
|
|
|
|
|
|
|
อยากสอบถามเรื่องการเขียน foreach ซ้อน foreach เเล้วใช้ฟังก์ชั่น if else มาเป็นเงื่อนไขในการตรวจสอบอาร์เรย์ที่กำหนดอ่ะคะ
โดยกำหนดให้
Code (PHP)
$Consonant = array("ก","ข","ค","ฆ","ง","จ","ฉ","ช","ซ","ฌ","ญ","ฎ","ฏ","ฐ","ฑ","ฒ","ณ","ด","ต","ถ","ท","ธ","น","บ","ป","ผ","ฝ","พ","ฟ","ภ","ม","ย","ร","ล","ว","ศ","ษ","ส","ห","ฬ","อ","ฮ");
$Diphthongs= array("ร ","ล","ว");
$Vowel= array("ะ","า","ิ","ี","ึ","ื","ุ","ู","เะ","เ","แะ","แ","โะ","โ","เาะ","อ","เอะ","เอ","เียะ","เีย","เือะ","เือ","ัวะ","ัว","ฤ","ฤา","ฦ","ฦา","ำ","ใ","ไ","เา");
$Itone_marks=array("่","้","๊","๋","็","ั","์");
//เรียกใช้ฟังก์ชั่น foreach เพื่อตรวจสอบค่า $DATA1[0] เป็นพยัญชนะหรือเปล่า??
foreach (array($DATA1[0]) as $a)
{
foreach($Consonant as $z)
{
if($a == $z)
{
echo "พยางค์แรก อักขระที่ 1 เป็นพยัญชนะ = " . $z ."<br>";
}
}
}
ปัญหาของหนูคือว่า จากโค้ดนี้หนูต้องการตรวจสอบค่า $DATA1[0] อีกครั้งนึงว่าเป็นสระหรือป่าว?? ถ้าตำแหน่ง $DATA1[0] เป็นสระให้ย้ายค่าไป DATA2[0] แทน
หนูจะต้องเขียนโค้ดยังไงคะ??รบกวนผู้รู้ช่วยแนะนะด้วยค่ะ
Tag : PHP
|
|
|
|
|
|
Date :
2013-10-13 15:21:21 |
By :
นะโม |
View :
3811 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จะทำซับซ้อนไปทำไมครับ
Code (PHP)
$str = str_split("ต้องเขียนยังไงคะ");
$Consonant = array("ก","ข","ค","ฆ","ง","จ","ฉ","ช","ซ","ฌ","ญ","ฎ","ฏ","ฐ","ฑ","ฒ","ณ","ด","ต","ถ","ท","ธ","น","บ","ป","ผ","ฝ","พ","ฟ","ภ","ม","ย","ร","ล","ว","ศ","ษ","ส","ห","ฬ","อ","ฮ");
$Diphthongs= array("ร ","ล","ว");
$Vowel= array("ะ","า","ิ","ี","ึ","ื","ุ","ู","เะ","เ","แะ","แ","โะ","โ","เาะ","อ","เอะ","เอ","เียะ","เีย","เือะ","เือ","ัวะ","ัว","ฤ","ฤา","ฦ","ฦา","ำ","ใ","ไ","เา");
$Itone_marks=array("่","้","๊","๋","็","ั","์");
foreach($str as $a){
if(in_array($a,$Consonant){
echo 'พยัญชนะ';
}elseif(in_array($a,$Diphthongs){
//..........ต่อเองนะครับ
}
}
|
|
|
|
|
Date :
2013-10-13 20:39:20 |
By :
โปรแกรมมั่ว |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|