Problem: Read array of array into flat array [message #170868] |
Sat, 04 December 2010 11:27 |
gina
Messages: 2 Registered: December 2010
Karma: 0
|
Junior Member |
|
|
Hey there.
I am having a problem with that array and I don't seem to get my head round
so thought I better ask for some good help ;)
....
foreach ($detailsArray as $details) {
$counter++;
foreach ($details as $key => $value) {
$arrayData[] = array(
'id'.$counter => $value->getId(),
'detail'.$counter => $value->getDetailText()
);
}
rather than an array of array I'd like to have an array containing the
values all in a flat form
the function should return an array like:
$resultArray = array('id1' =>'1', detail1 => 'ABC', id2 =>'1', detail2 =>
'DEF');
How am I going to achieve this ?
TIA gin
|
|
|
Re: Problem: Read array of array into flat array [message #170871 is a reply to message #170868] |
Sat, 04 December 2010 12:17 |
Michael Fesser
Messages: 215 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
.oO(gina)
> I am having a problem with that array and I don't seem to get my head round
> so thought I better ask for some good help ;)
>
>
> ...
> foreach ($detailsArray as $details) {
> $counter++;
> foreach ($details as $key => $value) {
>
> $arrayData[] = array(
> 'id'.$counter => $value->getId(),
> 'detail'.$counter => $value->getDetailText()
> );
> }
>
>
>
> rather than an array of array I'd like to have an array containing the
> values all in a flat form
>
> the function should return an array like:
>
> $resultArray = array('id1' =>'1', detail1 => 'ABC', id2 =>'1', detail2 =>
> 'DEF');
>
>
> How am I going to achieve this ?
foreach (…) {
$arrayData['id'.$counter] = $value->getId();
$arrayData['detail'.$counter] = $value->getDetailText();
}
Micha
|
|
|
Re: Problem: Read array of array into flat array [message #170872 is a reply to message #170871] |
Sat, 04 December 2010 12:23 |
gina
Messages: 2 Registered: December 2010
Karma: 0
|
Junior Member |
|
|
Hallo Micha.
Vielen lieben Dank ... manchmal steh ich einfach aufm Schlauch!!!
Gruß Gina :)
"Michael Fesser" <netizen(at)gmx(dot)de> schrieb im Newsbeitrag
news:67ckf6tt72h3b0vis6vm8v4k4b1fe1b8d8(at)mfesser(dot)de...
> .oO(gina)
>
>> I am having a problem with that array and I don't seem to get my head
>> round
>> so thought I better ask for some good help ;)
>>
>>
>> ...
>> foreach ($detailsArray as $details) {
>> $counter++;
>> foreach ($details as $key => $value) {
>>
>> $arrayData[] = array(
>> 'id'.$counter => $value->getId(),
>> 'detail'.$counter => $value->getDetailText()
>> );
>> }
>>
>>
>>
>> rather than an array of array I'd like to have an array containing the
>> values all in a flat form
>>
>> the function should return an array like:
>>
>> $resultArray = array('id1' =>'1', detail1 => 'ABC', id2 =>'1', detail2 =>
>> 'DEF');
>>
>>
>> How am I going to achieve this ?
>
> foreach (…) {
> $arrayData['id'.$counter] = $value->getId();
> $arrayData['detail'.$counter] = $value->getDetailText();
> }
>
> Micha
|
|
|