tonelm54
asked on
last element in array
Im trying to build by own binder for binding to mysql (long story.....)
So I want to pass the data via an array:-
But when I look at the array only the last element of parameter is stored:-
What I want to be able to do is list all the parameters, like:-
I understand that the each parameter is overwriting its previous, but would like to know how I can get around this, so I can this working.
Thank you
So I want to pass the data via an array:-
$arr = array('sqlCode'=>"INSERT INTO CountryLanguage (`code`,`language`,`official`,`percent`) VALUES (?, ?, ?, ?)",
'parameter'=>array('field'=>'code', 'type'=>'s', 'value'=>'DEU', 'post'=>'txtCode' ),
'parameter'=>array('field'=>'language', 'type'=>'s', 'value'=>'Bavarian', 'post'=>'txtLanguage' ),
'parameter'=>array('field'=>'official', 'type'=>'s', 'value'=>'F', 'post'=>'txtOfficial' ),
'parameter'=>array('field'=>'percent', 'type'=>'d', 'value'=>'11.2', 'post'=>'txtPercent' ));
But when I look at the array only the last element of parameter is stored:-
Array
(
[sqlCode] => INSERT INTO CountryLanguage (`code`,`language`,`official`,`perce nt`) VALUES (?, ?, ?, ?)
[parameter] => Array
(
[field] => percent
[type] => d
[value] => 11.2
[post] => txtPercent
)
)
What I want to be able to do is list all the parameters, like:-
foreach ($arr['parameter'] as $value) {
echo $value['field'];
}
I understand that the each parameter is overwriting its previous, but would like to know how I can get around this, so I can this working.
Thank you
ASKER
Is there anyway to call them the same?
What I want to do is list the child array elements inside the elements with the
What I want to do is list the child array elements inside the elements with the
foreach ($arr['parameter'] as $value) {
echo $value['field'];
}
Can you please give me some sample output?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To make it simpler read this:
Then you can use your foreach() on the array. Hooray!
$arr=array('sqlCode'=>"INSERT INTO CountryLanguage (`code`,`language`,`official`,`percent`) VALUES (?, ?, ?, ?)");
$p1=array('field'=>'code', 'type'=>'s', 'value'=>'DEU', 'post'=>'txtCode' );
$p2=array('field'=>'language', 'type'=>'s', 'value'=>'Bavarian', 'post'=>'txtLanguage' );
$p3=array('field'=>'official', 'type'=>'s', 'value'=>'F', 'post'=>'txtOfficial' );
$p4=array('field'=>'percent', 'type'=>'d', 'value'=>'11.2', 'post'=>'txtPercent' );
$arr['parameters']=array($p1,$p2,$p3,$p4);
Then you can use your foreach() on the array. Hooray!
Therefore you should use different names, such as parameter1, parameter2, etc.
If you have any further questions, feel free to ask me.