Jump to content

Array Question


Joe Haley

Recommended Posts

This is pretty much the example on the php website, but i wanted to try it out. The original is on here:
http://uk2.php.net/manual/en/function.key.php

[code]
<?php
$array[] = 'whatever';
while ($array_test = current($array)) {
  if ($array_test == 'whatever') {
      echo key($array);
  }
  next($array);
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/15046-array-question/#findComment-60507
Share on other sites

Seems a little... complex.

I did think of something, however:

$key = count($array);
if ($key != 0)
$key--;

$array[$key] = 'whatever';
return($key);

as it is just a numericly indexed array.


Edit:
ooohhh, key() is just what is needed!

$array[] = '';
end($array);
return key($array);
Link to comment
https://forums.phpfreaks.com/topic/15046-array-question/#findComment-60516
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.