Ich versuche, Elemente zu einem assoziativen Array hinzuzufügen, dies ist für ein Zend-Formular (die Auswahloptionen), aber aus irgendeinem Grund sind die Werte nicht die gleichen wie die Option.Kann mir bitte jemand sagen, warum dies kein assoziatives Array erstellt?
Ich bin mit
$thearray[$test->address1] = $test->address1;
was ich erwarten würde sowohl der Schlüssel und der Wert genau gleich sein (der Wert von $test->address1
). Was passiert ist, dass der Schlüssel nummeriert ist (0,1,2,3,4 usw.), aber der Wert ist korrekt, hat jemand irgendwelche Ideen warum?
Hier ist mein Code
$tests = json_decode($result);
$testtwo = $tests->_embedded->house ;
$thearray = array();
foreach ($testtwo as $test) {
$i = $test->address1;
$thearray[$test->address1] = $test->address1;
};
und dann wird die Form wie diese
array(365) {
[0]=> string(18) "1 property address"
[1]=> string(27) "2 another address"
[2]=> string(18) "3 another addresst"
....
var_dump von $ Test wäre
$this->add(array(
'name' => 'address',
'type' => 'Select',
'options' => array(
'label' => 'Address',
'value_options' => $thearray,
'disable_inarray_validator' => true,
),
'attributes' => array(
'class' => 'form-control',
'id' => 'propertyaddress',
),
));
Var_dump des Arrays
erstellt (innerhalb der Schleife)object(stdClass)#271 (11) {
["id"]=> string(1) "1" ["address1"]=> string(22) "1 property address"
["address2"]=> NULL
["town"]=> string(10) "the town"
["city"]=> string(10) "The city"
["county"]=> string(10) "The county" ["postcode"]=> string(8) "NN11 1NN"
...
print_r von $ Ergebnis wäre
{
"_links":{
"self":{
"href":"http:\/\/shop.dev\/house?page=1"
},
"first":{
"href":"http:\/\/shop.dev\/house"
} ,
"last":{
"href":"http:\/\/shop.dev\/house?page=1"
}
},
"_embedded" :{
"house":[
{
"id":"1",
"address1":"1 property address",
"address2":null,
"town":"town",
"city":"city",
"county":"county",
"postcode":"NN11 1NN",
"branch":"BRANCH NAME",
"propertytype":"property type",
"landlord":"Landlord name",
"_links":{
"self":{
"href":"http:\/\/shop.dev\/house\/1"
}
}
}
zeigen Bitte beachten Sie die Inhalte der verschiedenen Arrays in Frage – Steve
auch 'var_dump ($ test);' wäre hilfreich. –
Und die ursprüngliche JSONString in $ Ergebnis bitte – RiggsFolly