RE: [PHP] the numeric key of an array???

2002-12-20 Thread John W. Holmes
 How can i do for printing the value of an array given the numeric key
for
 example i have this code:
 
 $array = array (
 'VAL1' = VALUE1,
 'VAL2' = VALUE2,
 'VAL3' = VALUE3
 )
 
 So the only way i have found to print the value is like this :
 echo $array['VAL1'];
 
 and it prints = VALUE1 but i want to know if its possible to do it
 something
 like this:
 echo $array[0];
 i mean give the numeric key for printing VALUE1 so instead the string
key
 (VAL1) use the numerc (0)

You can't, because there is no key of zero in that array. All arrays are
associative, so the only way to use $array[0] is to define $array[0]. 

If you're looking to loop through your array, there are other methods.

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] the numeric key of an array???

2002-12-20 Thread Philip Olson

No, but you can do this:

  $arr2 = array_values($array);

  print $arr2[0]; // VALUE1

Regards,
Philip Olson


On Fri, 20 Dec 2002, Alexander Guevara wrote:

 How can i do for printing the value of an array given the numeric key for
 example i have this code:
 
 $array = array (
 'VAL1' = VALUE1,
 'VAL2' = VALUE2,
 'VAL3' = VALUE3
 )
 
 So the only way i have found to print the value is like this :
 echo $array['VAL1'];
 
 and it prints = VALUE1 but i want to know if its possible to do it something
 like this:
 echo $array[0];
 i mean give the numeric key for printing VALUE1 so instead the string key
 (VAL1) use the numerc (0)
 
 Thanks in advance!
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] the numeric key of an array???

2002-12-20 Thread Alexander Guevara
Well which kind of methods are you talking about?? could you tell me some
for do it??

Thanks!

John W. Holmes [EMAIL PROTECTED] wrote in message
01c2a890$d1539cf0$7c02a8c0@coconut">news:01c2a890$d1539cf0$7c02a8c0@coconut...
  How can i do for printing the value of an array given the numeric key
 for
  example i have this code:
 
  $array = array (
  'VAL1' = VALUE1,
  'VAL2' = VALUE2,
  'VAL3' = VALUE3
  )
 
  So the only way i have found to print the value is like this :
  echo $array['VAL1'];
 
  and it prints = VALUE1 but i want to know if its possible to do it
  something
  like this:
  echo $array[0];
  i mean give the numeric key for printing VALUE1 so instead the string
 key
  (VAL1) use the numerc (0)

 You can't, because there is no key of zero in that array. All arrays are
 associative, so the only way to use $array[0] is to define $array[0].

 If you're looking to loop through your array, there are other methods.

 ---John W. Holmes...

 PHP Architect - A monthly magazine for PHP Professionals. Get your copy
 today. http://www.phparch.com/





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] the numeric key of an array???

2002-12-20 Thread Alexander Guevara
Yeah this workes fine.. thanks!!

Philip Olson [EMAIL PROTECTED] wrote in message
Pine.BSF.4.10.10212210135051.36987-10@localhost">news:Pine.BSF.4.10.10212210135051.36987-10@localhost...

 No, but you can do this:

   $arr2 = array_values($array);

   print $arr2[0]; // VALUE1

 Regards,
 Philip Olson


 On Fri, 20 Dec 2002, Alexander Guevara wrote:

  How can i do for printing the value of an array given the numeric key
for
  example i have this code:
 
  $array = array (
  'VAL1' = VALUE1,
  'VAL2' = VALUE2,
  'VAL3' = VALUE3
  )
 
  So the only way i have found to print the value is like this :
  echo $array['VAL1'];
 
  and it prints = VALUE1 but i want to know if its possible to do it
something
  like this:
  echo $array[0];
  i mean give the numeric key for printing VALUE1 so instead the string
key
  (VAL1) use the numerc (0)
 
  Thanks in advance!
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] the numeric key of an array???

2002-12-20 Thread John W. Holmes
  If you're looking to loop through your array, there are other
methods.

 Well which kind of methods are you talking about?? could you tell me
some
 for do it??

foreach($array as $key=$value)

www.php.net/foreach

while(list($key,$value) = each($array)

www.php.net/each
www.php.net/list

$cnt = count($array);
for($x=0;$x$cnt;$x++)

www.php.net/count

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] the numeric key of an array???

2002-12-20 Thread Alexander Guevara
Thanks.

it worked fine.. and the reply at the botton too..

Thank you so much!
John W. Holmes [EMAIL PROTECTED] wrote in message
000101c2a896$70aad5c0$7c02a8c0@coconut">news:000101c2a896$70aad5c0$7c02a8c0@coconut...
   If you're looking to loop through your array, there are other
 methods.

  Well which kind of methods are you talking about?? could you tell me
 some
  for do it??

 foreach($array as $key=$value)

 www.php.net/foreach

 while(list($key,$value) = each($array)

 www.php.net/each
 www.php.net/list

 $cnt = count($array);
 for($x=0;$x$cnt;$x++)

 www.php.net/count

 ---John W. Holmes...

 PHP Architect - A monthly magazine for PHP Professionals. Get your copy
 today. http://www.phparch.com/





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php