San artaigil seo, ionnsaichidh tu mar a nì thu ath-shuidheachadh air taobh a-staigh sreath. Le bhith ag ath-shuidheachadh tha e a ’ciallachadh a’ phuing a ghluasad gus a bhith a ’comharrachadh a’ chiad eileamaid den raon a tha na ghiùlan àbhaisteach aig a ’phuing. Bidh an gnìomh ath-shuidheachadh () a ’coileanadh an gnìomh seo.
Dè an co-chòrdadh a th ’aig a’ ghnìomh ath-shuidheachadh () ann am PHP?
reset(array)
paramadair | Fiosrachadh |
---|---|
sreath | An raon gus am puing a-staigh de - Riatanach ath-shuidheachadh |
Eisimpleirean de dhreuchd ath-shuidheachadh ()
Eisimpleir 1. Faigh luach gnàthach, an ath luach na sreath, agus an uairsin thoir sùil air a ’phuing às deidh dhut ath-shuidheachadh.
<?php
$arr= array("Jawad", "Ahmad", "Sumerina");
echo current($arr);
echo next($arr);
echo reset($arr);
?>
Eisimpleir 2. San eisimpleir seo, gheibh thu a h-uile modh co-cheangailte ris an roinn modh ath-shuidheachadh. Bidh na modhan sin ag obair le comharradh a-staigh nan arrays.
<?php
$members= array("Jawad", "Ahmad", "Sumerina", "ACS");
// Current element: Jawad
echo current($people) . "<br>";
// Next element of Jawad: Ahmad
echo next($people) . "<br>";
// Now the current element: Ahmad
echo current($people) . "<br>";
// Previous element of Ahmad: Jawad
echo prev($people) . "<br>";
// Last element: ACS
echo end($people) . "<br>";
// Previous element of ACS: Sumerina
echo prev($people) . "<br>";
// Current element: Sumerina
echo current($people) . "<br>";
// Move the internal pointer to the first element of the array:Jawad
echo reset($people) . "<br>";
// Next element of Jawad: Ahmad
echo next($people) . "<br>";
// Get key and value of Ahmad (current element) then moves the internal pointer forward
print_r (each($members));
?>