Dies funktioniert für mich
if (is_array($array)) {
$obj = new StdClass();
foreach ($array as $key => $val){
$key = str_replace("-","_",$key)
$obj->$key = $val;
}
$array = $obj;
}
stellen Sie sicher, dass str_replace es als ‚-‘ in Variablennamen in PHP nicht erlaubt ist, sowie:
Regeln für Variablen
* A variable name must start with a letter or an underscore "_"
* A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _)
* A variable name should not contain spaces. If a variable name is more than one word, it should be separated with an underscore ($my_string), or with capitalization ($myString)
So benennen, da diese in Arrays erlaubt sind, wenn Jeder von ihnen kommt im $ Schlüssel aus dem Array, das Sie konvertieren, Sie werden böse Fehler haben.
Die besten Antworten sind oft die einfachsten +1 – alex