ok here how I set it PHP: private $test = [];$this->test[] = 1 . " " . $player->getName(); How would I echo “1" only (I need name for something else)
What context is this? If each name will have a different number, use the number as the key for the string entry. If each player will have a number, possibly duplicate, do what DaPigGuy mentioned. If you need both with a different key, save it as a multidimensional array or string with a semicolon or something that you can use to explode later on.
PHP: $this->test[] = "1Steve";$number = intval($this->test[0]{0}); // int 1$name = substr($this->test[0], 1); // Steve Just answer the damn question
That's hacky. It will fail when the number is more than two digits long. And you forgot to ltrim the name (also, he needs help with "1 Steve" not "1steve"). It's either a solution or a quality solution.
Maybe saving as number:name Like $this->test[] = "94:Steve" He can $value = explode(":", "94:Steve"); to get the values. So $value[0] is the number and $value[1] the name
Or you could save yourself from exploding the string and casting the number to int (or ignore the casting) everytime, if you used the number as the index if that's a possibility.
I'm obviously taking a piss. Perhaps store the number digits count along with this hash? (Again - taking a piss)
Why people ignore such good posts as Yours? I would go with one of these two solutions PHP: $this->test[1] = "Steve";$this->test["Steve"] = 1; Unless you're writing to file you don't have to do any encoding/decoding (wtf anyway)