How to assign value of array to existing object property. I tried this and got error.
$fieldss = array("name"=>"User Name", "fields"=>"10091437300560754");
$list = object(stdClass)[325]
public 'id' => string '1' (length=1)
public 'form_id' => string '6' (length=1)
public '10091437300560754' => string 'Ronaldo' (length=9)
//then I tried to access:
$list->$fieldss['fields']; which equals to 'Ronaldo'.
//but It gives undefined property:$10091437300560754;
Above: $fieldss['fields'] = "10091437300560754";
and $list->$fieldss['fields']
means $list->10091437300560754
but why I get undefined property. Please help.
I tried my code in localhost with PHP v5.3.8 It worked fine But When I uploaded to server in which PHP v5.4. It gives me error like above
10091437300560754 is not a valid variable/property name. A valid variable name starts with a letter or underscore , followed by any number of letters, numbers, or underscores.
I have tried this and it's working fine at my end.
$fieldss = array("name" => "User Name", "fields" => "10091437300560754");
$list = (object) array('id' => '1',
'form_id' => '6',
'10091437300560754' => 'Ronaldo');
echo "<pre>";
print_r($list);
//then I tried to access:
echo $list->$fieldss['fields'];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.