Jump to content

[SOLVED] is there a function for this?


Michdd

Recommended Posts

It's a really simple question, I browsed the manual and couldn't find something to what I wanted.

 

Basically I have an array of objects that'll be added to and removed from often. Every time an object is removed I call array_values(&$array) so it'll keep the lowest possible indexes. However when I use $array[] = 'something'; the index of that element it puts in isn't the lowest possible.

Link to comment
https://forums.phpfreaks.com/topic/174516-solved-is-there-a-function-for-this/
Share on other sites

Nope, that's not it. Let me try to explain it a bit better.

 

Here's an example:

 

$array = Array("something", "something");
//Keys would be 0, 1
unset($array[0]);
//Keys: 1
array_values(&$array);
//Keys are now 0
$array[] = "something";
//Keys are 0, 2

I want it to be 0, 1. Not 0, 2

It's not necessarily really that critical. But I have a Character class, then my Server class has an array of these Character classes. I want to keep the key of each Character instance within that array the same as it's id and keep them at their lowest possible value, just to keep it organized.

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.