إعادة تعيين PHP () الوظيفة
مثال
أخرج قيمة العنصر الحالي والعنصر التالي في المصفوفة ، ثم أعد تعيين المؤشر الداخلي للمصفوفة إلى العنصر الأول في المصفوفة:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
echo next($people) . "<br>";
echo reset($people);
?>
التعريف والاستخدام
تعمل وظيفة إعادة التعيين () على تحريك المؤشر الداخلي إلى العنصر الأول في المصفوفة.
الطرق ذات الصلة:
- Current () - تُرجع قيمة العنصر الحالي في المصفوفة
- end () - ينقل المؤشر الداخلي إلى العنصر الأخير في المصفوفة ويخرجه
- next () - ينقل المؤشر الداخلي إلى العنصر التالي في المصفوفة ويخرجه
- prev () - ينقل المؤشر الداخلي إلى العنصر السابق في المصفوفة ويخرجه
- كل () - تُرجع مفتاح العنصر الحالي وقيمته ، وتحرك المؤشر الداخلي للأمام
بناء الجملة
reset(array)
قيمه المعامل
Parameter | Description |
---|---|
array | Required. Specifies the array to use |
تفاصيل تقنية
قيمة الإرجاع: | تُرجع قيمة العنصر الأول في المصفوفة عند النجاح أو FALSE إذا كانت المصفوفة فارغة |
---|---|
إصدار PHP: | 4+ |
مزيد من الأمثلة
مثال
عرض لجميع الأساليب ذات الصلة:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>"; // The current element is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
echo current($people) . "<br>"; // Now the current element is Joe
echo prev($people) . "<br>"; // The previous element of Joe is Peter
echo end($people) . "<br>"; // The last element is Cleveland
echo prev($people) . "<br>"; // The previous element of Cleveland is Glenn
echo current($people) . "<br>"; // Now the current element is Glenn
echo reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, which is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
print_r (each($people)); // Returns the key and value of the current element (now Joe), and moves the internal pointer forward
?>
❮ مرجع مصفوفة PHP