Portrety Uliczne Nieznajomych - zobacz wyjątkową galerię portretów z warszawskich ulic
ZALOGUJ SIĘ
login:
hasło:
przypomnij hasło
załóż konto użytkownika
(i zobacz kilka porad gratis)
   
WYSZUKIWARKA I DZIAŁY
całe porady  tytuły
zaznacz działy do przeszukania
(brak wyboru = wszystkie działy)
PHP
MySQL >
PostgreSQL
SQLite
Perl
Java
XML
XSLT
XPath
WML
SVG
RegExp
Wyszukiwarki
Ochrona
VBScript
Google Plus
XHTML/CSS
JavaScript
Grafika
Flash
Photoshop
Windows
Linux
Bash
Apache
Procmail
E-biznes
Explorer
Opera
Firefox
Inne porady
   
KURSY, DOKUMENTACJE
Własne:
XHTML/CSS
JavaScript
ActionScript
WML, RSS, SSI
Pozostałe:
PHP
MySQL
Java API
więcej...
   
użytkowników online: 45
W CZYM MOGĘ POMÓC?


   
OPINIE UŻYTKOWNIKÓW
Uważam, że serwis jest najlepszy na świecie. Wykonany rzetelnie, a wszystkie skrypty sa dopracowane. Zamieszczony materiał godny mistrza. Jestem programistą od wielu lat i bez tego serwisu nie istnieje. Upraszacza życie każdemu programiście. Imponujący jest fakt, że do twórcy serwisu zawsze można się zwrócić z prośbą o pomoc i uzyskuje się ją w bardzo krótkim czasie. Najważniejsze w tym wszystkim jest to, że można korzystać z witryny za symboliczną opłatą.

Marcin Kowalski
Multinet Polska

   
GALERIA FOTOGRAFII
   
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net

[Spis] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [X] [W] [Z]

reset

(PHP 3, PHP 4, PHP 5)

reset --  Ustaw wewnętrzny wskaźnik tablicy na jej pierwszy element

Opis

mixed reset ( array &tablica )

reset() przewija wewnętrzny wskaźnik tablicy parametru tablica na jego pierwszy element i zwraca jego wartość, lub FALSE jeśli tablica jest pusta.

Przykład 1. Przykład użycia funkcji reset()

<?php

$tablica
= array('krok pierwszy', 'krok drugi', 'krok trzeci', 'krok czwarty');

// domyślnie, wskażnik jest na pierwszym elemencie
echo current($tablica) . "<br />\n"; // "krok pierwszy"

// przeskocz dwa kroki
next($tablica);
next($tablica);
echo
current($tablica) . "<br />\n"; // "krok trzeci"

// zresetuj wskaźnik, zacznik od nowa na pierwszym kroku
reset($tablica);
echo
current($tablica) . "<br />\n"; // "krok pierwszy"

?>

Patrz także: current(), each(), next() i prev().




User Contributed Notes

Alexandre Koriakine
18-Nov-2005 11:09

Also it's good to reset this way the multidimentional arrays:

reset($voo2['moder']);
while (list($key, $value) = each ($voo2['moder'])) {

reset($voo2['moder'][$key]);
while (list($key1, $value1) = each ($voo2['moder'][$key])) {
#do what u want
}

}


s_p_a_mcatcher at hotmail dot com
02-Dec-2004 07:30

Be aware that when using reset() to clear an element and key from an array, if auto-incrementing, the new array keys will not reset a key previously set:

$temparray[] = "0";
$temparray[] = "1";
$temparray[] = "2";
unset($temparray[2]);
$temparray[] = "2";
$temparray[] = "3";

print_r($temparray);

The above will return:
Array
(
   [0] => 0
   [1] => 1
   [3] => 2
   [4] => 3
)

When attempting something like this, its better to use array_pop().

hope it helped


leaetherstrip at inbox dot NOSPAMru
17-Oct-2004 03:54

Note that reset() will not affect sub-arrays of multidimensional array.

For example,

<?php
   $arr
= array(
      
1 => array(2,3,4,5,6),
      
2 => array(6,7,8,9,10)
   );
  
   while(list(
$i,) = each($arr))
   {
       echo
"IN \$arr[$i]<br>";
      
       while(list(
$sub_i,$entry) = each($arr[$i]))
       {
           echo
"\$arr[$i][$sub_i] = $entry<br>";
       }
   }
  
  
reset($arr);

  
// Do the same again
  
while(list($i,) = each($arr))
   {
       echo
"IN \$arr[$i]<br>";
      
       while(list(
$sub_i,$entry) = each($arr[$i]))
       {
           echo
"\$arr[$i][$sub_i] = $entry<br>";
       }
   }
?>

will print

IN $arr[1]
$arr[1][0] = 2
$arr[1][1] = 3
$arr[1][2] = 4
$arr[1][3] = 5
$arr[1][4] = 6
IN $arr[2]
$arr[2][0] = 6
$arr[2][1] = 7
$arr[2][2] = 8
$arr[2][3] = 9
$arr[2][4] = 10
IN $arr[1]
IN $arr[2]


kevin at oceania dot net
19-Jul-2003 03:54

Here is a simple example on how to combine 2 arrays. Here we use array_combine() to create list of months and there respective month number. The same result could just as easily be achieved with array('1'=>'January') etc.

<?php
                                                                                                            
 
// make it or break it
 
error_reporting(E_ALL);
                                                                                                            
 
// create and array of keys
 
$keys = range(1,12);
                                                                                                            
 
// create an array of months
 
$months = array(
 
'January',
 
'February',
 
'March',
 
'April',
 
'May',
 
'June',
 
'July',
 
'August',
 
'September',
 
'October',
 
'November',
 
'December'
);
                                                                                                            
 
// combine the arrays
 
$combined_array = array_combine($keys, $months);
                                                                                                            
 
// echo out the results
 
foreach($combined_array as $k=>$v){ echo $k.' -> '.$v.'<br />'; }
                                                                                                            
?>


jules
12-Jun-2003 09:29

Be aware that if you give an empty array to reset(), what you'll get back is a boolean. consider...

     $myarray = array();
     $ret = reset($myarray);
     echo 'reset has type '. gettype($ret) .' and val * '. $ret;
     if( $ret )
     {
       echo '*. But it evaluates true';
     }
     else
     {
       echo '*. It evaluates false';
     }
     if( is_null($ret) )
     {
       echo ', and appears null';
     }
     {
       echo ', and appears not null';
     }
    
     echo '.';

<output>
reset has type boolean and val * *. It evaluates false, and appears not null.
</output>

<bleaugh/>


tac at smokescreen dot org
26-Sep-2001 08:42

Related to resetting an array is resetting a result set back to the beginning, so you can loop through it again.  To do that, use

mysql_data_seek($result, 0)

I use this often when debugging -- do a query, print it out, then loop through it a second time to process.  I'm adding this here under Reset because that's where I originally looked for this functionality.


02-Jul-2001 04:30

A cleaner (better?) way would be to use is_array() instead:

if (is_array($form_array)) {
   [array stuff here]
}


kk at shonline dot de
30-Jul-1998 02:22

When used on a scalar or unset value, reset() spews warning messages. This is often a problem when accessing arrays generated from HTML form input data: these are scalar or unset if the user didn't enter sufficient information.

You can silence these error messages by prefixing an @ (at sign) to reset(), but it is better style to protect your reset() and the following array traversal with an if (isset()). Example code:

if (isset($form_array)) {
  reset($form_array);
  while (list($k, $v) = each($form_array) {
   do_something($k, $v);
  }
}


 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt