# Passing structure to PHP function

- Thread: https://externals.io/message/12310
- Original archive: https://news-web.php.net/php.internals/12310
- Started by Michael Spector on 2004-08-23T17:56:08+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #12310 — Michael Spector — 2004-08-23T17:56:08+00:00

URL: https://externals.io/message/12310#12310

Hi,

I'm "translating" some function, that recieves a pointer to structure of
this type:

struct {
    char * text;
    char ** value;
    int flags;
};

and I'm get stuck here, thinking of a legal way how to pass the list of
structures to my PHP function. I thought to pass it in this way:

myfunc (
		array(
			array("text" => $text1, "value" => &$value1, "flags" => flags1),
			array("text" => $text2, "value" => &$value2, "flags" => flags2),
			...
		)
);

but, I wonder whether this way is acceptable? Anyway, is there another
solution to this problem?

Thanks.


-- 
Best regards,

Michael

---

## #12311 — Rasmus Lerdorf — 2004-08-23T18:10:16+00:00

URL: https://externals.io/message/12310#12311 · In reply to: #12310

> I'm "translating" some function, that recieves a pointer to structure of
> this type:
>
> struct {
>     char * text;
>     char ** value;
>     int flags;
> };

This looks like a string, an array and an integer to me.  So just pass
that.  Or an array of those if there is more than one.

-Rasmus

---

## #12312 — Michael Spector — 2004-08-23T18:33:48+00:00

URL: https://externals.io/message/12310#12312 · In reply to: #12311

> 
> > […]
> 
> This looks like a string, an array and an integer to me.  So just pass
> that.  Or an array of those if there is more than one.
> 

Actually, the prototype of the function is the following:

int newtWinEntries (char * title, char * text, int suggestedWidth, int flexDown, int flexUp, int dataWidth, struct newtWinEntry * items, char * button1, ...)

Where newtWinEntry is the structure mentioned above.
The problem is that I have to accept a list of such structures as an
argument. Value (char ** value) is the reference to the returned value.

So, you say there's no need to use string keys in the array ?


-- 
Best regards,

Michael
