0

I would like to insert value to an array's inner arrays specific item.

So I have an array which is loosing data between functions which I can't finde where and when it should be printed out some values are missing, but I can get these values from an object and I would like to inject the object's items to the array's inner arrays [value] item. In the object I have the same names as in the array.

The objet looks like this

Userinfos Object
(
    [address_type] => BT
    [address_type_name] => 
    [company] => 
    [title] => 
    [last_name] => Last Name
    [first_name] => First Name
    [middle_name] => 
    [phone_1] => 1234567
    [phone_2] => 
    [fax] => 
    [address_1] => Street address
    [address_2] => 
    [city] => City
    [virtuemart_state_id] => 0
    [virtuemart_country_id] => 97
    [zip] => 1234
    [agreed] => 0
    [created_on] => 0000-00-00 00:00:00
    [created_by] => 0
    [modified_on] => 2012-08-08 22:04:36
    [modified_by] => 853
    [email] => webmaster@universumpoker.com
    [username] => webmaster@universumpoker.com
)

and the array looks like this

Array
(
    [email] => Array
        (
            [name] => email
            [value] => 
            [title] => E-Mail
            [type] => emailaddress
            [required] => 1
            [hidden] => 
            [formcode] => <input type="text" maxlength="100" class="required" value="" size="30" name="email" id="email_field"> 
        )

    [last_name] => Array
        (
            [name] => last_name
            [value] => 
            [title] => Last Name
            [type] => text
            [required] => 1
            [hidden] => 
            [formcode] => <input type="text" maxlength="32" class="required" value="" size="30" name="last_name" id="last_name_field"> 
        )

    [first_name] => Array
        (
            [name] => first_name
            [value] => 
            [title] => First Name
            [type] => text
            [required] => 1
            [hidden] => 
            [formcode] => <input type="text" maxlength="32" class="required" value="" size="30" name="first_name" id="first_name_field"> 
        )
)

As you can see in this array the [value] is empty and in [formcode] the input's value is empty too.

So is there any way to push the Object's values to the array. I was looking into array_push but couldn't figure out how target [value]

Laci K
  • 585
  • 2
  • 8
  • 24

1 Answers1

0

Can you not simply set the value like so:

$array->first_name[$index]->value = $userinfos->first_name

in a loop around all your user info?

peacemaker
  • 2,541
  • 3
  • 27
  • 48
  • Upps sorry I hit enter to early :D Oh it's a good idea maybe I was over thinking it but I'm not sure if I do a foreach in foreach to get the userInfos wont mess up everthing. – Laci K Aug 08 '12 at 23:10
  • I print it out like this foreach($this->data["fields"] as $_field) { echo $_field['formcode'] . "\n"; } the I use the rest of the array for adding class to html tags – Laci K Aug 08 '12 at 23:15
  • Yes, you can start out doing a `foreach` over the userinfo array, then inside that foreach set all the sub arrays based upon the outer loop index. i.e. the index = the users id in the array. – peacemaker Aug 08 '12 at 23:53