PHP array_walk_recursive()ฟังก์ชั่น
ตัวอย่าง
เรียกใช้แต่ละองค์ประกอบอาร์เรย์ในฟังก์ชันที่ผู้ใช้กำหนด:
<?php
function myfunction($value,$key)
{
echo "The key $key has the value $value<br>";
}
$a1=array("a"=>"red","b"=>"green");
$a2=array($a1,"1"=>"blue","2"=>"yellow");
array_walk_recursive($a2,"myfunction");
?>
ความหมายและการใช้งาน
ฟังก์ชัน array_walk_recursive() เรียกใช้แต่ละองค์ประกอบอาร์เรย์ในฟังก์ชันที่ผู้ใช้กำหนดเอง คีย์และค่าของอาร์เรย์เป็นพารามิเตอร์ในฟังก์ชัน ความแตกต่างระหว่างฟังก์ชันนี้และฟังก์ชันarray_walk() คือฟังก์ชันนี้ช่วยให้คุณสามารถทำงานกับอาร์เรย์ที่ลึกกว่า (อาร์เรย์ภายในอาร์เรย์)
ไวยากรณ์
array_walk_recursive(array, myfunction, parameter...)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
array | Required. Specifying an array |
myfunction | Required. The name of the user-defined function |
parameter,... | Optional. Specifies a parameter to the user-defined function. You can assign one parameter to the function, or as many as you like. |
รายละเอียดทางเทคนิค
คืนมูลค่า: | ส่งกลับ TRUE เมื่อสำเร็จหรือ FALSE เมื่อล้มเหลว |
---|---|
รุ่น PHP: | 5+ |
❮ การอ้างอิงอาร์เรย์ PHP