arrays - PHP how to assign class property variables conditionally -


I am new to php classes, arrays, etc., so pls excuse me if I do not use the correct terminology example For example:

Let's say I have an example, for example:

For example:

For example: a class test and " Test "is an asset" employee "(hopefully this is the right way of calling) and the employee is of a complex type.

So, I have something like this:

$ test -> Employee = array ('age' = & gt; '30 ',' gender '= & gt; $ gender,' nationality '= & gt; $ nationality,' marital status' => $ position, etc., etc.) My problem here is whether 'age', 'sex', 'nationalism', etc. are not always present and I want to specify the value of them. Assigned , and I do not want to use, if not for each combination of each empty values ... (this is a small example, but I have many of these qualities or whatever is said and many "if" combinations are very messy ...)

I have these values I am sending it as a soap request and I do not want any empty XML tags ...

If my terminology is not correct, but I hope to help someone to help me Has been clarified enough!

In advance, Pablo

How about: < Pre = $ array = array ('age' = & gt; '30', 'sex' => $ sex, 'nationality' => $ nationality, 'marriage' => $ s Tatus); Forex currency ($ array = $ value as $ key) {if (is_null ($ value)} $ value == "") {unset ($ array [$ key]); }} $ Test-> Employee = $ array;


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -