AUTO
[ID/PWã±â] [ȸ¿ø°¡ÀÔ]
´º½º¿Í Á¤º¸ (276)
ÀÚÀ¯ °Ô½ÃÆÇ (392)
°¡ÀÔ Àλç (1960)
°øÁö»çÇ× (5)
AJAX ÇнÀ (72)
ASP Áú¹® (71)
ASP ÇнÀ (271)
MYSQL ÇнÀ (73)
SQLSERVER ÇнÀ (337)
¿À¶óŬ ÇнÀ (66)
µ¥ÀÌŸº£À̽º ÇнÀ (29)
¾×¼Ç½ºÅ©¸³Æ® ÇнÀ (261)
¾×¼Ç½ºÅ©¸³Æ® Áú¹® (65)
ÆÛ¿Â Ç÷¡½Ã (204)
Ç÷¡½Ã ³×ºñ°ÔÀÌ¼Ç (59)
Ç÷¡½Ã ¼Ò½º (532)
Ç÷¡½Ã ¿¬±¸½Ç (536)
Ç÷¡½Ã Áú¹® (647)
Ç÷¡½Ã °ÔÀÓ (53)
Ç÷¡½Ã ÀÎÆ®·Î (44)
Ç÷¡½Ã ÀÌÆåÆ® (45)
ÀÚÀÛ Ç÷¡½Ã (83)
ű×,HTML Áú¹® (43)
ű×,HTML ÇнÀ (131)
ÀÚ¹Ù,JSP ÇнÀ (161)
ÀÚ¹Ù,JSP Áú¹® (70)
ÀÚ¹Ù½ºÅ©¸³Æ® ÇнÀ (223)
ÀÚ¹Ù½ºÅ©¸³Æ® ¼Ò½º (73)
ÀÚ¹Ù½ºÅ©¸³Æ® Áú¹® (79)
Æ÷Åä¼¥ Áú¹® (108)
Æ÷Åä¼¥ ÇнÀ (369)
Ãßõ À̹ÌÁö (239)
ÀÚÀÛ À̹ÌÁö (81)
ÆÛ¿Â À̹ÌÁö (445)
PHP Áú¹® (62)
PHP ÇÔ¼ö (2658)
PHP ÇнÀ (661)
ÇÁ·Î±×·¡¹Ö ÇнÀ (205)
ÀÎÅͳݼ­¹ö ÇнÀ (346)
ÀÎÅͳݼ­¹ö Áú¹® (22)
³×À̹ö ¼Ó ȨÇǵðÀÚÀδåÄÄ
´ÙÀ½ ¼Ó ȨÇǵðÀÚÀδåÄÄ
±¸±Û ¼Ó ȨÇǵðÀÚÀδåÄÄ
¿¥ÆÄ½º ¼Ó ȨÇǵðÀÚÀδåÄÄ
¾ßÈÄ ¼Ó ȨÇǵðÀÚÀδåÄÄ
³×ÀÌÆ® ¼Ó ȨÇǵðÀÚÀδåÄÄ
½ÎÀÌ¿ùµå ȨÇǵðÀÚÀδåÄÄ
¿¥¿¡½º¿£ ȨÇǵðÀÚÀδåÄÄ
  ȨÇǵðÀÚÀδåÄÄ > PHP ÇÔ¼ö
   
  PHP current
  ±Û¾´ÀÌ : ¼Õ´Ô     ³¯Â¥ : 05-12-20 15:01     Á¶È¸ : 1771    
   http://cafe.naver.com/q69/9325 (293)

current

(PHP 3, PHP 4 , PHP 5)

current -- ¹è¿­ÀÇ ÇöÀç ¿ø¼Ò¸¦ ¹ÝȯÇÑ´Ù

¼³¸í

mixed current ( array array)

¸ðµç ¹è¿­Àº "ÇöÀç" ¿ø¼Ò¸¦ °¡¸®Å°´Â ³»ºÎ Æ÷ÀÎÅ͸¦ °®´Âµ¥, ÀÌ ³»ºÎ Æ÷ÀÎÅÍ´Â ¹è¿­¿¡ »ðÀԵǾîÁø ù¹øÂ° ¿ø¼Ò·Î ÃʱâÈ­µÈ´Ù.

current() ÇÔ¼ö´Â ´Ü¼øÈ÷ ÇöÀç ³»ºÎ Æ÷ÀÎÅÍ¿¡¼­ °¡¸®Å°°í ÀÖ´Â ¹è¿­ ¿ø¼ÒÀÇ °ªÀ» ¹ÝȯÇÑ´Ù. ¾î¶² ¹æ¹ýÀ¸·Îµç ±× Æ÷ÀÎÅ͸¦ ¿òÁ÷ÀÌÁö ¾Ê´Â´Ù. ³»ºÎ Æ÷ÀÎÅͰ¡ ¿ø¼Ò ¸ñ·ÏÀÇ ³¡¿¡¼­ ¹þ¾î³­ °÷À» °¡¸®Å°¸é, current()´Â FALSE¸¦ ¹ÝȯÇÑ´Ù.

ÁÖÀÇ

¹è¿­ÀÌ ºó ¿ø¼Ò¸¦ Æ÷ÇÔÇϸé(0 À̳ª "", ºó ¹®ÀÚ¿­) ÀÌ ÇÔ¼ö´Â ÀÌ ¿ø¼Òµé¿¡ ´ëÇØ¼­µµ FALSE¸¦ ¹ÝȯÇÑ´Ù. current()¸¦ »ç¿ëÇÏ¿© ±× ¹è¿­ ¾ÈÀÇ ¸ñ·Ï ³¡ÀÎÁö È®ÀÎÇÒ¼ö ¾ø°Ô ¸¸µç´Ù. ºó ¿ø¼Ò¸¦ Æ÷ÇÔÇÒ¼öµµ ÀÖ´Â ¹è¿­À» ÀûÀýÇÏ°Ô °Å´Ò±â À§Çؼ­´Â, each() ÇÔ¼ö¸¦ ÀÌ¿ëÇÑ´Ù.

¿¹ 1. current()ÀÇ »ç¿ë¿¹¿Í °ü·Ã ÇÔ¼ö

<?php
$transport
= array('foot', 'bike', 'car', 'plane'
);
$mode = current($transport);
// $mode = 'foot';
$mode = next($transport);   
// $mode = 'bike';
$mode = current($transport);
// $mode = 'bike';
$mode = prev($transport);   
// $mode = 'foot';
$mode = end($transport);   
// $mode = 'plane';
$mode = current($transport);
// $mode = 'plane';
?>

end(), key(), next(), prev(), reset() Âü°í.



add a note add a note User Contributed Notes
current
toreriks at hotmail dot com
05-Aug-2005 01:18
By doing some small changes to the last post, one can make the function seek not just from the start in a forward manner but also from the end or from a relative position both forwards and backwards.
E.g to seek backwards from a relative position one would supply 'current' as $start, and 'prev' as $iter.

function array_set_current(&$array, $key, $start='reset', $iter='next'){
   $start($array);
   while (current($array)!==FALSE){
       if (key($array) == $key) {
           break;
       }
       $iter($array);
   }
   return current($array);
}
jari dot eskelinen at iki dot fi
02-Dec-2004 01:08
mattblisset's array_set_current has one flaw: if you have array with key 0, while-loop will stop there. Fixed version:

function array_set_current(&$array, $key){
   reset($array);
   while (current($array)!==FALSE){
       if (key($array) == $key) {
           break;
       }
       next($array);
   }
   return current($array);
}
mdeng at kabenresearch dot com
24-Apr-2004 06:04
For large array(my sample was 80000+ elements), if you want to traverse the array in sequence, using array index $a[$i] could be very inefficient(very slow). I had to switch to use current($a).
mattblissett at hotmail dot com
01-Jan-2004 10:36
Sam said:
"Here is a function that sets the current pointer of an array to a given key."

If your array pointer doesn't start at the beginning, this won't work for moving the pointer to a lower one. So, use a reset() first:

<?php
//set the pointer of an array to the given key
function array_set_current(&$array, $key
){
  
reset($array
);
   while(
current($array
)){ 
       if(
key($array) == $key
){
           break;
       }
      
next($array
);
   }
}
?>

HTH,
Matt
vitalib at 012 dot net dot il
02-Dec-2003 10:10
Note that by copying an array its internal pointer is lost:

<?php
$myarray
= array(0=>'a', 1=>'b', 2=>'c'
);
next($myarray
);
print_r(current($myarray
));
echo
'<br>'
;
$a = $myarray
;
print_r(current($a
));
?>

Would output 'b' and then 'a' since the internal pointer wasn't copied. You can cope with that problem using references instead, like that:

<?php
$a
=& $myarray
;
?>
jdpipe at yahoo dot co dot uk
24-Nov-2003 05:08
You can't get a pointer to an element in an array using the 'current' construct, for example:

<?php

$a
=array();

$a[]='aaa'
;
$a[]='bbb'
;
$a[]='ccc'
;
$a[]='ddd'
;
$a[]='eee'
;

reset($a
);
next($a
);
$v =& current($a
);
$v = 'xxxx'
;

// array is not changed
print_r($a
);

next($a
);

$v =& $a[key($a
)];
$v = 'yyy'
;

// now the array is changed
print_r($a
);

?>
si
15-Sep-2003 05:57
current isn't able to return by reference, eg.

function &getDataPacket()
{
global $globalref;
return current( $globalref[ key( $globalref ) ]->dp ); // *FAILS*
return $globalref[ key( $globalref ) ]->dp[ key( $globalref[ key( $globalref ) ]->dp ) ]; // *WORKS*
}

According to Bug#12692 it's intentional, so watch out!
tipman
08-May-2003 11:07
if you got a array with number as index you get the last index with this:

eg:
$array[0] = "foo";
$array[1] = "foo2";

$lastKey = sizeof($array) - 1;

only a little help :)
kyle
17-Mar-2003 11:49
The comment by 'someone out there' is wrong according to the warning.  If I read the warning right, if there are elements with empty values, it will die. 

look at array_keys, it does what is described there, and probably faster too.  Then loop through that (since all numeric indices, simple for loop should work:

$keys=array_keys($myarr);
for($x=0;$x<count($keys);$x++) {
   ...
}

though foreach is probably recommended)
php4all at free dot fr
12-Mar-2003 03:37
There is an other way to grag the key and the value of an Array:

<?
foreach($myArray as $Key => $Value
) {
   echo
"Key:" . $Key
;
   echo
"Value:" . $Value

}
?>

Then you will have the key and the value of each element in the Array.

php4all
someone out there
11-Mar-2003 10:42
here's a way to grab array keys:

reset($myArray);

while (current($myArray) !== false) {
   $myKey = key($myArray);
   echo $myKey; //do as you will with each key
   next($myArray);
}
retestro_REMOVE at SPAM_esperanto dot org dot il
02-Mar-2003 02:31
The docs do not specify this, but adding to the array using the brackets syntax:
     $my_array[] = $new_value;
will not advance the internal pointer of the array. therefore, you cannot use current() to get the last value added or key() to get the key of the most recently added element.

You should do an end($my_array) to advance the internal pointer to the end ( as stated in one of the notes on end() ), then

     $last_key = key($my_array);  // will return the key
     $last_value = current($my_array);  // will return the value

If you have no need in the key, $last_value = end($my_array) will also do the job.

- Sergey.

   

 
´º½º¿Í Á¤º¸ ¡¤ ÀÚÀ¯ °Ô½ÃÆÇ ¡¤ °¡ÀÔ ÀÎ»ç ¡¤ °øÁö»çÇ× ¡¤ AJAX ÇнÀ ¡¤ ASP Áú¹® ¡¤ ASP ÇнÀ ¡¤ MYSQL ÇнÀ ¡¤ SQLSERVER ÇнÀ ¡¤ ¿À¶óŬ ÇнÀ ¡¤ µ¥ÀÌŸº£À̽º ÇнÀ ¡¤ ¾×¼Ç½ºÅ©¸³Æ® ÇнÀ ¡¤ ¾×¼Ç½ºÅ©¸³Æ® Áú¹® ¡¤ ÆÛ¿Â Ç÷¡½Ã ¡¤ Ç÷¡½Ã ³×ºñ°ÔÀÌ¼Ç ¡¤ Ç÷¡½Ã ¼Ò½º ¡¤ Ç÷¡½Ã ¿¬±¸½Ç ¡¤ Ç÷¡½Ã Áú¹® ¡¤ Ç÷¡½Ã °ÔÀÓ ¡¤ Ç÷¡½Ã ÀÎÆ®·Î ¡¤ Ç÷¡½Ã ÀÌÆåÆ® ¡¤ ÀÚÀÛ Ç÷¡½Ã ¡¤ ű×,HTML Áú¹® ¡¤ ű×,HTML ÇнÀ ¡¤ ÀÚ¹Ù,JSP ÇнÀ ¡¤ ÀÚ¹Ù,JSP Áú¹® ¡¤ ÀÚ¹Ù½ºÅ©¸³Æ® ÇнÀ ¡¤ ÀÚ¹Ù½ºÅ©¸³Æ® ¼Ò½º ¡¤ ÀÚ¹Ù½ºÅ©¸³Æ® Áú¹® ¡¤ Æ÷Åä¼¥ Áú¹® ¡¤ Æ÷Åä¼¥ ÇнÀ ¡¤ Ãßõ À̹ÌÁö ¡¤ ÀÚÀÛ À̹ÌÁö ¡¤ ÆÛ¿Â À̹ÌÁö ¡¤ PHP Áú¹® ¡¤ PHP ÇÔ¼ö ¡¤ PHP ÇнÀ ¡¤ ÇÁ·Î±×·¡¹Ö ÇнÀ ¡¤ ÀÎÅͳݼ­¹ö ÇнÀ ¡¤ ÀÎÅͳݼ­¹ö Áú¹®¡¤ Ç÷¡½Ã »ùÇà ¼Ò½º ¡¤ Ç÷¡½Ã äÆÃ¹æ ¡¤ Ç÷¡½Ã ¹Ì´ÏȨÇÇ ¡¤ Ç÷¡½Ã °¶·¯¸® ¡¤ Ç÷¡½Ã RSS¸®´õ ¡¤ Ç÷¡½Ã PHP »çÀü ¡¤ Ç÷¡½Ã ¿ìÆí¹øÈ£ ã±â ¡¤ Ç÷¡½Ã ÇÑÀÚ°ÔÀÓ ¡¤ Ç÷¡½Ã ´Þ·Â°ú½Ã°è ¡¤ Ç÷¡½Ã Æ÷Åä¶óÀ̺귯¸® ¡¤ ·£´ýÀ̹ÌÁö ¡¤ Ç÷¡½Ã ´Þ·Â°ú½Ã°è ¡¤ ÇÑ±Û µµ¸ÞÀÎ ¡¤ ³×À̹ö ºí·Î±× ½ºÅ©·¦ ¡¤ ½ÎÀÌ¿ùµå ¹Ì´ÏȨÇÇ °¶·¯¸® ¡¤ ½ÎÀÌ¿ùµå ¹Ì´ÏȨÇÇ µî·Ï ¡¤ ÇÁ·Î°ÔÀÌ¸Ó ·©Å© ¡¤ ȨÆäÀÌÁöÁ¤º¸ ºí·Î±×
Copyright ¨Ï hompy.info. All rights reserved.