|
Posted by Benjamin on 08/15/07 02:33
ben@spam.com wrote:
> Pretty new to php so sorry if this is an obvious question.
>
> I want to create an array that contains a tuple, i.e. a pair of
> values.
>
> e.g. myarray[$key] = ($firstname,$lastname)
>
> I would then need a function that returns only the first or second
> member of the tuple.
>
> The tuple could also be a list, provided there's a function for only
> returning the value at a particular index value of the list.
>
> I am sure there is an obvious way to accomplish the same thing in php
> (without using a multi-dimensional array) but it is escaping me at the
> moment.
No, (if only we had Python) you have to use a multi-dimensional array:
myarray[$key] = array($firstname, $lastname);
function getFirstName(name) {
return name[0];
}
function getLastName(name) {
return name[1];
}
>
> Ben
Navigation:
[Reply to this message]
|